• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

create a new window in a JFrame

 
Eric Crockett
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A modal JDialog is exactly what you want.
 
Eric Crockett
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic