How can I get just one instance of JFrame when I click on JButton?
Every time I click on the button I got a new JFrame over the old one.
I want to use one instance of the frame(and should be the first instance I created it when I click on the button) every time I click on the button
please help me.
Rob Prime wrote:Check out the singleton design pattern. You can use lazy initialization since you should only create frames from the Event Dispatcher Thread.
I checked it out, too complicated code examples for newbie like me... Can anyone provide simpler code?
something like that
if (someFrame isvisible==true) put it on top
else someframe.setVisible(true);
First, create the JFrame when you create all the other components of your GUI. Don't make it visible just yet.
Then, when the controller button is clicked, just make it visible. You don't need to test whether it is visible; if it were visible you wouldn't be able to see the button and click it.
oyu already have a JButton showing, so you must already have a JFrame (JWindow etc) showing,
and when you click the button you only want a single 'other' JFrame to appear.
if this is correct, change the 2nd JFrame to a modal JDialog, which will prevent the JButton from being clicked
whilst the JDialog is showing
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...