jframe

Position on Screen Right Bottom

☆樱花仙子☆ 提交于 2019-11-27 04:46:24
问题 I need to position JFrame on my screen. But I can't make them appear on the right side of the screen bottom. Please can someone explain me how to position them, if you can describe how to do it, it would be great. Here is the code so far. //Gets the screen size and positions the frame left bottom of the screen GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen

Center JDialog over parent

我只是一个虾纸丫 提交于 2019-11-27 04:45:42
I have a Java swing application with a button that produces a popup window when a certain action is performed. I'd like to align the center point of the popup window with the center point of the parent window when it is rendered. How can I calculate the x,y coordinates to plug into setLocation() for the popup window? Just to clarify. I do not want the behavior of setLocationRelativeTo() because that sets the top-left pixel of the popup over the center pixel of the parent frame. I want to set the center pixel of the popup over the center pixel of the parent frame. setLocationRelativeTo ..this

How to remove title bar in JFrame

喜欢而已 提交于 2019-11-27 04:37:02
I'm using the following code for practising, http://docs.oracle.com/javase/tutorial/uiswing/examples/layout/BorderLayoutDemoProject/src/layout/BorderLayoutDemo.java I also add frame.setSize(frame.getMaximumSize()); in createAndShowGUI() method, What is more I want this window not to have the title bar, close and minimize buttons. I tried the following code, frame.setUndecorated(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); If I added this code before the pack(), it goes into infine loop with this exception Exception in thread "AWT-EventQueue-0" java.lang

How can I remove just the Maximize button from a JFrame?

馋奶兔 提交于 2019-11-27 04:27:12
问题 I have a JFrame and want to remove the maximize button from that. I wrote the code below, but it removed maximize, minimize, and close from my JFrame . JFrame frame = new JFrame(); frame.add(kart); frame.setUndecorated(true); frame.setVisible(true); frame.setSize(400, 400); I want to only remove the maximize button from the JFrame . 回答1: Make it not resizable: frame.setResizable(false); You will still have the minimize and close buttons. 回答2: You can't remove the button from a JFrame . Use a

Java - how do I prevent WindowClosing from actually closing the window

拥有回忆 提交于 2019-11-27 04:26:22
问题 I seem to have the reverse problem to most people. I have the following pretty standard code to see if the user wants to do some saves before closing the window: frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { boolean close = true; // check some files, asking if the user wants to save // YES and NO handle OK, but if the user hits Cancel on any file, // I want to abort the close

Java - How to create a custom dialog box?

◇◆丶佛笑我妖孽 提交于 2019-11-27 03:53:38
I have a button on a JFrame that when clicked I want a dialog box to popup with multiple text areas for user input. I have been looking all around to try to figure out how to do this but I keep on getting more confused. Can anyone help? If you don't need much in the way of custom behavior, JOptionPane is a good time saver. It takes care of the placement and localization of OK / Cancel options, and is a quick-and-dirty way to show a custom dialog without needing to define your own classes. Most of the time the "message" parameter in JOptionPane is a String, but you can pass in a JComponent or

How to show different cards in a CardLayout?

早过忘川 提交于 2019-11-27 03:36:27
问题 I looked at a code example that used this code: cl.show(cardPanel, "" + (currentCard)); But when I use show I get a message in Eclipse that it's deprecated and I wonder if there is another way to show the different cards in the CardLayout when I click on the buttons? Below is the code for my CardLayout class. Suggestions are also welcome if some part of the code are bad practise. Thanks! import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax

Using the coordinate plane in the JFrame

北城以北 提交于 2019-11-27 03:34:20
问题 //I am trying to learn how to draw objects in java. I'm getting better at it, but once I get an image on the screen I am having trouble manipulating it. The numbers I put in don't make sense to how the shapes are turning out. At least to me they don't. In algebra if you increase a number on the x axis it goes to the right and if you increase a number on the y axis it goes up. Thats not whats happening here. Can anyone explain to me how this works? I'm still new to java, so the more

Adding image to JFrame

此生再无相见时 提交于 2019-11-27 03:25:15
问题 So I am using Eclipse with Windows builder. I was just wondering if there was anyway I can import an image that'll show up on the JFrame that I can easily move around and re-size instead of setting the location and size and drawing it. 回答1: There is no specialized image component provided in Swing (which is sad in my opinion). So, there are a few options: As @Reimeus said: Use a JLabel with an icon. Create in the window builder a JPanel, that will represent the location of the image. Then add

Drawing an Image to a JPanel within a JFrame

有些话、适合烂在心里 提交于 2019-11-27 02:49:19
问题 I am designing a program that contains two JPanels within a JFrame, one is for holding an image, the other for holding GUI components(Searchfields etc). I am wondering how do I draw the Image to the first JPanel within the JFrame? Here is a sample code from my constructor : public UITester() { this.setTitle("Airplane"); Container container = getContentPane(); container.setLayout(new FlowLayout()); searchText = new JLabel("Enter Search Text Here"); container.add(searchText); imagepanel = new