views:

572

answers:

1

I have a JInternalFrame window that needs to popup a modal dialog box when a JButton is pressed. At first, I tried using JDialog, but I found that JDialog constructor needs:

  1. JFrame
  2. boolean modal

I tried passing JInternalFrame to it, but the type didn't match.

Should I use JDialog with JInternalFrame? What if I dont specify the owner (i.e. passing a null)? Is there anything wrong with that?

+1  A: 
SwingUtilities.getAncestorOfClass(Window.class, myButton)

The abvove method will return the Window that contains your button. Once you have it you can pass it to the constructor of the dialog :)

EDIT1: I misread the question I guess. How can you have a JinternalFrame as the topmost window??

EDIT2: Also if you pass null to Jdialog constrcutor then by default it uses a shared owner i.e SwingUtilities.getSharedOwnerFrame()

Suraj Chandran
ok, I'm going to try it now. As a sidenote, this also means that it's perfectly normal to use JDialog with JInternalFrame correct?
ShaChris23
Sorry, I'm not being clear. I have a JFrame as my topmost window, who contains a bunch of JInternalFrames. The button belongs to JInternalFrame however.
ShaChris23
Okay..I just tried it; I think it works fine. (I haven't connected the JDialog's button to any actionPerformed yet, but i can at least popup a dialog box when I press my JInternalFrame's button!) Thanks!
ShaChris23
@shachris23..no dear you can't pass a internalframe to jdialog. jdialog only supports window,frame and diaolg in its constructor. but ofcourse you can use both internalframe and a dialog together in your app..:)
Suraj Chandran
@shachris23...also please check EDIT2 in the above answer:)
Suraj Chandran