I got a JFrame, which is created by a method invoked by a Button.
Works fine.
Now I want to let the method check if the JFrame is already open,
because it's not necessary to open it again.
Any way to do this?
I searched java.sun.com and this newsgroup, bu to no avail.
Any help welcomed
The place to look for such things is the API documentation.
Window.isShowing(), or Component.isVisible() (both inherited by JFrame)
might be what you want.
/Thomas
Make your dialog a private member of the class
and null it in the constructor. Then in the
actionPerformed() method you do something
like this:
// Create on first access
if (dialog == null) {
dialg = new JFrame();
... other init stuff ...
}
// Show it
dialog.setVisible (true);
This program does what you're looking for.
Check how yours is different:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test implements ActionListener
{
private JFrame dialog_ = null;
public void actionPerformed (ActionEvent event)
{
if (dialog_ == null)
dialog_ = new JFrame("TEST");
dialog_.setVisible (true);
}
public static void main (String args[])
{
JFrame f = new JFrame();
f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JButton b = new JButton ("Dialog...");
b.addActionListener (new Test());
f.getContentPane().add (b);
f.pack();
f.setVisible (true);
}
}
Hmm, still doesn't work.
Does it matter that cardDialog is a JInternalFrame?
Maybe the JInternalFrame 's DefaultCloseOperation doesn't dispose of it
the way I suppose it would?
Should I alter the JInternalFrames DefaultCloseOperation?
JDesktopPane.getAllFrames()