0

I'm trying to add a JFrame (bar) to a JFrame (foo), which would force bar to be closed before foo can be intergrated with once again.

Such as this, where the "About Eclipse" frame must be closed before I can write code once again:

Example

Something like this won't do the trick (simplified):

JFrame foo = new JFrame("Base");
JFrame bar = new JFrame("About");
foo.add(bar); // IllegalArgumentException: adding a window to a container

How to achieve this?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Zar
  • 6,786
  • 8
  • 54
  • 76
  • 4
    This has been asked ***many*** times here and elsewhere. Use a modal JDialog or JOptionPane, not another JFrame. Don't try to add a top level window (JFrame) to another top level window. [The dialog tutorials](http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html) will explain some of the details and the JDialog and [JOptionPane](http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html) APIs will explain the rest. – Hovercraft Full Of Eels Oct 06 '12 at 14:16

1 Answers1

3

You can use a JDialog like this

JFrame foo = new JFrame("Base");
JDialog bar = new JDialog(foo, "About", true);
daniel
  • 3,166
  • 2
  • 17
  • 18