jframe

Java wait for JFrame to finish

穿精又带淫゛_ 提交于 2019-11-29 11:55:40
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. 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 frame create the CountDownLatch with a count down of 1 and pass this latch to the login frame. Then have

How do I hide the current JPanel and show a new one with a button in Java?

蹲街弑〆低调 提交于 2019-11-29 11:38:04
I unfortunately have to use multiple windows in this program and I don't think CardLayout is going to work because I can't have any buttons constant between the different layouts. So I'm trying to code a button to hide the present JPanel (thePanel) and show a new one (thePlacebo). I'm trying to hide thePanel in an ActionListener like this: frame.getContentPane().remove(thePanel); I thought this would work, but it just freezes my program as soon as I hit the button. Here's a chunk of the code for context: public class Reflexology1 extends JFrame{ JButton button1, button2; JButton movingButton;

JFrame inside another JFrame

痴心易碎 提交于 2019-11-29 11:09:17
I have a game of chess. I have written 3 classes. 1st if for game. (chessboard, pieces, and so on) And another one is for menu. (buttons like new, open, set time) Both of them use JFrame. I would like to put both classes mentioned above into the 3rd class. For example the Game window would be on the left, and the menu on the right. The third class would also show the whole app by JFrame. How to do that? You can't put one JFrame inside another. You have a couple of design choices here. You can change your JFrames to JPanels. This is probably the easiest change. On the other hand, you can look

How to pass a variable value from one JFrame to Another JFrame in Netbeans

家住魔仙堡 提交于 2019-11-29 11:00:37
I have two JFrames login.java and account.java I need to get the username from the login.java page and put it in a variable in the account.java JFrame . How can I do this in the Java NetBeans using the Swing? Instead of Using JFrames for passing values between different forms you can use CardLayout which will persist your data which you have entered in the previous form. All you have to do is Create a JFrameForm and add panels to it. Vinay You can use getter and setter methods... Set the username in a setter. And using object of login.java use it in account.java through getter... public class

refresh JFrame after adding new Components

情到浓时终转凉″ 提交于 2019-11-29 10:59:01
问题 I want to add some new Components to my JFrame during runtime when a button is pressed. This works so far, but i have to resize the window manually to see the new components. Is there any Action I can fire or a method to call to refresh the window? Any help appreciated. Thanks in advance. 回答1: You have to revalidate(); the frame. If that doesn't work you also have to call repaint(); 回答2: Call revalidate(); repaint(); revalidate tells the layout manager to reset based on the new component list

setMaximumSize not working in java

我只是一个虾纸丫 提交于 2019-11-29 10:46:05
I hava a java program with a JFrame I am using absolute positioning here is my main function public static void main(String[] args) { ape Ape = new ape(); Ape.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Ape.setSize(1000,1000); Ape.setMinimumSize(new Dimension(1000,1000)); Ape.setMaximumSize(new Dimension(1000,1000)); Ape.setVisible(true); } When I run the program I try to resize it and make the window smaller but I can't when I try to make the window bigger it works fine I basicly skips the setMaximumSize() function I have read around and aparently this has happened before is this a known

Java getting download progress

你。 提交于 2019-11-29 10:36:56
I am writing a Java application (Using NetBeans as an IDE and a jFrame form), and one part of it downloads a file. How can I update a progress bar with the current progress of the download, or at least get the total amount of currently downloaded bytes in another thread? Below is a part of my code: Runnable updatethread = new Runnable() { public void run() { try { java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("server/package.zip").openStream()); java.io.FileOutputStream fos = new java.io.FileOutputStream("package.zip"); java.io.BufferedOutputStream bout =

How to add text to JFrame?

家住魔仙堡 提交于 2019-11-29 10:08:21
So I am designing a JFrame using Eclipse WindowBuilder. This specific frame is an error message stating that the user provided invalid credentials. I have added a button to exit the frame and I now need to display the actual error message "The login credentials specified are invalid. Please provide valid credentials." I have done some searching and everyone says to use a JLabel, but when I create my JLabel and enter the text to it, there is no wordwrap or anything so I can't fit the label inside my frame. What is an easy way to simply display a message in the center of the JFrame? Bhavik

setSize() doesn't work for JFrame

五迷三道 提交于 2019-11-29 09:59:47
import javax.swing.JFrame; import javax.swing.SwingUtilities; class Demo { JFrame jf; Demo() { jf=new JFrame("Demo"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(5000,5000); jf.setVisible(true); System.out.println(jf.getSize()); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Demo(); } }); } } I use jf.setSize(5000, 5000) for JFrame but after that getSize returns other size: java.awt.Dimension[width=1386,height=788] (my screen resolution is 1366x768) Can I set frame size greater than screen size?

Drawing a line on a JFrame

穿精又带淫゛_ 提交于 2019-11-29 09:57:59
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 = (Graphics2D) g; Line2D lin = new Line2D.Float(100, 100, 250, 260); g2.draw(lin); } public static void main