wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes create a new window in a JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "create a new window in a JFrame" Watch "create a new window in a JFrame" New topic
Author

create a new window in a JFrame

Eric Crockett
Greenhorn

Joined: Jan 24, 2005
Posts: 25
I would like to have a typical JFrame, and then have a menu to open a new "popup" window. I can handle the main frame and the menu, but the new JFrame? I want to be "attached" to the other JFrame.
Examples of these windows are everywhere, I want it to work just like a "Properties box". As it is now, when I click my button a new Frame is created, but it is not attached to the other one. I want the main frame to be disabled (I can do that) when the properties frame comes up, but I would rather it not create a new item in the taskbar. Specifically, I would like for whenever I click on the main frame in the taskbar, the properties window stays on top when it is open.

I hope what I am trying to do is clear...

Eric
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

A modal JDialog is exactly what you want.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Eric Crockett
Greenhorn

Joined: Jan 24, 2005
Posts: 25
That looks about right, as long as I can add JTextFields, JLists, JButtons etc to a panel (or just the Dialog itself) then that IS exactly what I want!

I have been messing around with JInternalFrame, any comment on why one would be better than the other?

Thanks
Eric
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Originally posted by Eric Crockett:
That looks about right, as long as I can add JTextFields, JLists, JButtons etc to a panel (or just the Dialog itself) then that IS exactly what I want!

A JDialog behaves exactly the same as a JFrame as far as setting layouts and adding components.

Prior to Java 1.5, you had to get a frame/dialog's content pane using getContentPane(). This Container could then be used to set the layout and add components just as regular containers like JPanel.
In Java 1.5 and up, you can set the layout of the frame/dialog directly, as well as add components. This will basically use the content pane in the background.

So if you already have a panel, you can call dialog.getContentPane().add(panel), or even dialog.setContentPane(panel).

I have been messing around with JInternalFrame, any comment on why one would be better than the other?

JInternalFrame is mostly used inside a JDesktopPane for an MDI environment; the JInternalFrame will not exit the JDesktopPane area. JDialog however can be used anywhere, will be shown on top of its parent frame (or dialog), and can be moved all over the screen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: create a new window in a JFrame