It's only two classes thus far. One has the bulk of the code and the other has a main method, which instantiates an object of type (the other class). In doing so, the constructor of the other class does appropriate operations as I'd like and then calls upon the display method.. but after it does that, the java swing window (JFrame) instantly closes.
Any ideas?
Here's the method that's supposed to do the displaying. it's not really what it's supposed to end up doing, but ... you get the idea (I hope) :p
// (javax.swing.* was imported at the top of the class)
public void displayStats()
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame fr = new JFrame("Statistician - Results");
fr.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JLabel label = new JLabel("hiiiii");
JComponent comp = new JTextArea();
fr.getContentPane().add(label);
fr.getContentPane().add(comp, 100);
fr.setSize(100,300);
fr.pack();
fr.setVisible(true);
}
Question
dt
Hi all,
Something strange is up with my app.
It's only two classes thus far. One has the bulk of the code and the other has a main method, which instantiates an object of type (the other class). In doing so, the constructor of the other class does appropriate operations as I'd like and then calls upon the display method.. but after it does that, the java swing window (JFrame) instantly closes.
Any ideas?
Here's the method that's supposed to do the displaying. it's not really what it's supposed to end up doing, but ... you get the idea (I hope) :p
Thanks,,
--dt
Link to comment
https://www.neowin.net/forum/topic/451064-java-swing-closes-immediately-after-opened/Share on other sites
12 answers to this question
Recommended Posts