jframe

Why does the JFrame setSize() method not set the size correctly?

强颜欢笑 提交于 2019-12-30 03:49:05
问题 So I've been programming in java for a semester or so, and I've had this problem a few times and finally got around to asking. If I make a JFrame and then set the size, like setSize(400,800) for example. The frame is not actually 800 pixels long. From what I can tell it is actually more like 770 (or maybe 769) pixels long. Also, if you set the vertical size very low (below 30), the frame doesn't even show up, only the top window bar from the OS and the frame doesn't get bigger until you go to

How to add data to JTable created in design mode?

安稳与你 提交于 2019-12-29 09:35:06
问题 I created an initial JFrame that contains a table with three columns, as shown below: This JFrame was created in design mode, and so now in the panel's constructor, I want to load some data so when the user selects to open this JFrame, the data is loaded. My column data types are Object (generally 'Status' is for an image representing the status of the share - active or inactive), String for the share's name and integer for the number of active clients connected to that share. My question is,

Resizing JFrame in one dimension

这一生的挚爱 提交于 2019-12-29 08:54:29
问题 I am trying to re-size my JFrame in only one dimension (width in this case) and I found this question JFrame re-sizable height ONLY which gave me a good answer for doing so; addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { setSize(new Dimension(preferredWidth, getHeight())); super.componentResized(e); } }); and I edited it slightly so that instead of locking width it locked height to a certain size and allowed width to be re-sizable.

Java: JFrame.setLocationRelativeTo(null) not centering the window on Ubuntu 10.04 / gnome 2.30.2 with OpenJDK 1.6.0_18

我的梦境 提交于 2019-12-29 08:34:20
问题 Sample code: JFrame jFrame = new JFrame("Test"); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setLocationRelativeTo(null); jFrame.setSize(600, 600); jFrame.pack(); // jFrame.setLocationRelativeTo(null); // same results jFrame.setVisible(true); Is this the OpenJDK's fault? I recall hearing it wasn't as good as Sun's, but since it became the standard for Ubuntu or whatever I decided to go along with it. The program is probably gonna run on windows, so I suppose I'm gonna have

Java GUI, Multiple Frames

半世苍凉 提交于 2019-12-29 08:23:08
问题 How do I go about creating what I describe below? First, here is the basic look of my GUI: When I click on Add New Account I want to have the GUI pop up a small window where the user can enter log-in credentials. I would need this information to be passed back into the main GUI, so I am lost as how to approach this. The same goes for Preferences or Remove Account . How do I go about creating a "GUI Overlay" of sorts. Sorry, I can't figure out the correct terminology for the effect I am

Java wait for JFrame to finish

佐手、 提交于 2019-12-29 08:11:41
问题 I have a login frame that i have to wait for from another thread. Upon successful login frame disposes itself. And i want to pop up the main frame for the application. Right now i am watching a boolean value to determine when to fire up the main frame. What is the correct way of doing this? Watching a boolean value just does not feel elegant. 回答1: If you have Java 5 or later available, you could use a CountDownLatch. For example, assuming the main frame is in control initially, have the main

Java wait for JFrame to finish

…衆ロ難τιáo~ 提交于 2019-12-29 08:11:07
问题 I have a login frame that i have to wait for from another thread. Upon successful login frame disposes itself. And i want to pop up the main frame for the application. Right now i am watching a boolean value to determine when to fire up the main frame. What is the correct way of doing this? Watching a boolean value just does not feel elegant. 回答1: If you have Java 5 or later available, you could use a CountDownLatch. For example, assuming the main frame is in control initially, have the main

Drawing a line on a JFrame

余生长醉 提交于 2019-12-29 07:32:28
问题 I am trying to draw a line using the Graphics 2D but then the line appears over all the other components in the JFrame thus making them invisible. How do I correct this problem? Here's the code : import javax.swing.*; import java.awt.*; import java.awt.geom.*; class Success extends JFrame{ public Success(){ JPanel panel=new JPanel(); getContentPane().add(panel); setSize(450,450); JButton button =new JButton("press"); panel.add(button); } public void paint(Graphics g) { Graphics2D g2 =

how to add a buffered image as back ground of JFrame then add a panel on this image? [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-29 02:04:07
问题 This question already has answers here : Background image JFrame with content (3 answers) Closed 6 years ago . I'm in the second term of Computer engineering . my problem is how to add JButton etc... on the background image ,you know I have written the below code , please help me to continue: as I said my JBotton can't be shown on the image and here is the problem. import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File;

Automatically size JPanel inside JFrame

拥有回忆 提交于 2019-12-28 15:12:58
问题 I have a JPanel subclass on which I add buttons, labels, tables, etc. To show on screen it I use JFrame : MainPanel mainPanel = new MainPanel(); //JPanel subclass JFrame mainFrame = new JFrame(); mainFrame.setTitle("main window title"); mainFrame.getContentPane().add(mainPanel); mainFrame.setLocation(100, 100); mainFrame.pack(); mainFrame.setVisible(true); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); But when I size the window, size of panel don't change. How to make size of