jframe

How to add support for resizing when using an undecorated JFrame?

心已入冬 提交于 2019-11-29 04:09:46
I would like to customize my titlebar, minimize-, maximize- and the close-button. So I used setUndecorated(true); on my JFrame, but I still want to be able to resize the window. What is the best way to implement that? I have a border on the RootPane, and I could use MouseListeners on the Border or the RootPane. Any recommendations? import java.awt.Color; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.border.LineBorder; public class UndecoratedFrame extends JFrame { private LineBorder border = new LineBorder

hiding title bar of JInternalFrame? -java

爷,独闯天下 提交于 2019-11-29 04:05:43
I found some code online, I edited it a bit. I want to hide title bar of a JInternalFrame. JInternalFrame frame = new JInternalFrame(); // Get the title bar and set it to null setRootPaneCheckingEnabled(false); javax.swing.plaf.InternalFrameUI ifu= frame.getUI(); ((javax.swing.plaf.basic.BasicInternalFrameUI)ifu).setNorthPane(null); frame.setLocation(i*50+10, i*50+10); frame.setSize(200, 150); //frame.setBackground(Color.white); frame.setVisible(true); desktop.add(frame); The problem is that the title bar isn't being hidden for some reason. Thanks. user2050146 First convert the internalframe

How can I display a BufferedImage in a JFrame?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 03:36:20
I want to display variations of the same image in the same JFrame, for example display an image in JFrame, then replace it with gray scale of the same image. ldog You will have to repaint the JFrame whenever you update the image. Here is what a simple google on the topic brings up: (I use those tutorials for all my Java coding) Java Tutorial: Drawing an Image Ian Will To build on camickr's solution (for the lazy like me who want quick code to copy/paste) here's a code illustration: JFrame frame = new JFrame(); frame.getContentPane().setLayout(new FlowLayout()); frame.getContentPane().add(new

How to layout multiple panels on a jFrame? (java)

亡梦爱人 提交于 2019-11-29 02:29:48
问题 I am in the process of making my own java socket game. My game is painting alright to the full screen (where it says "paint graphics here", but im painting to the whole jframe at the moment). I want to add a textbox with a scroll bar for displaying only text, not taking any input and another textbox to take text inputs from the user and then a button to send the text, for chat purposes. But onto my question, how do I even start to lay this out? I understand I need a layout, but can someone

Swing: set JFrame content area size

☆樱花仙子☆ 提交于 2019-11-29 01:16:30
I'm trying to make a JFrame with a usable content area of exactly 500x500. If I do this... public MyFrame() { super("Hello, world!"); setSize(500,500); } ... I get a window whose full size is 500x500, including the title bar, etc., where I really need a window whose size is something like 504x520 to account for the window border and titlebar. How can I achieve this? you may try couple of things: 1 - a hack: public MyFrame(){ JFrame temp = new JFrame; temp.pack(); Insets insets = temp.getInsets(); temp = null; this.setSize(new Dimension(insets.left + insets.right + 500, insets.top + insets

How to set a JFrame size to fit the CardLayout displayed JPanel?

时间秒杀一切 提交于 2019-11-29 00:16:27
I have a JFrame containing a set of JPanels in a CardLayout . Each JPanel has a different size and I want the JFrame to adapt to the size of the currently displayed JPanel (not the JPanel to adapt to the size of the JFrame ). How can I achieve this? The general is: if you have a layout problem, always solve it with an appropriate LayoutManager. Never tweak a component's sizing hint to reach your goal. In this case, it's particularly easy to adjust the CardLayout. By default, it calculates its prefSize to the max of prefSizes of all cards. Simply subclass and implement to return the prefSize

How to maximize a JFrame through code?

会有一股神秘感。 提交于 2019-11-28 22:21:11
How to maximize a JFrame through code? Try this: f.setExtendedState( f.getExtendedState()|JFrame.MAXIMIZED_BOTH ); this works perfectly till java 7 public class TEST { public static void main(String args[]) { JFrame jf= new JFrame(); jf.setVisible(true); jf.setExtendedState(JFrame.MAXIMIZED_BOTH); } } Swartblits Yea the Toolkit solution ignores the windows task bar and uses the full screen which is not what you want. For an immediate maximise of your form just add this in the JFrame constructor after the InitiateComponents() call. this.setExtendedState(JFrame.MAXIMIZED_BOTH); The class extends

How to make a JFrame really fullscreen?

别来无恙 提交于 2019-11-28 21:17:31
In my Java application I try to make a JFrame really fullscreen by using this code: public class MainFrame extends JFrame { private static final long serialVersionUID = 1L; public MainFrame() { super(); this.setTitle(); this.setUndecorated(true); this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.setVisible(true); //this.pack(); } } But on my Mac I can still see the Dock and the top toolbar of the OSX. So how can I create a JFrame that really consumes my whole screen? EDIT I have to add that I want to call that JFrame from a eclipse plugin. I haven't tried it yet, but Java has fullscreen API,

How to place a JButton at a desired location in a JFrame using Java

瘦欲@ 提交于 2019-11-28 21:15:20
问题 I want to put a Jbutton on a particular coordinate in a JFrame. I put setBounds for the JPanel (which I placed on the JFrame) and also setBounds for the JButton. However, they dont seem to function as expected. My Output: This is my code: import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Control extends JFrame { // JPanel JPanel pnlButton = new JPanel(); // Buttons JButton btnAddFlight = new JButton("Add Flight"); public

Opening a new JFrame from a Button

余生颓废 提交于 2019-11-28 14:48:06
I want to open a new JFrame by clicking a button (btnAdd); I have tried to create an actionlistener but I am having no luck; the code runs but nothing happens when the button is clicked. The methods in question are the last two in the following code. Any help is much appreciated! package AdvancedWeatherApp; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import