Skip to main content

About that WindowsUtils.findXXX()

1 reply [Last post]
Joined: 2003-06-13

Just in case I'm misunderstanding - I tried swapping out my singleton JFrame reference with one of these utility methods. But in cases like these I'm getting null back and a parentless dialog arrrgh!.

<br />
public class OpenAction extends AbstractAction {</p>
<p>  public void actionPerformed(ActionEvent event) {<br />
    JFrame frame = WindowUtils.findJFrame((Component) event.getSource());    // (its a menuitem but it'll return null)<br />
    AbstractDialog dialog = new AbstractDialog(frame, new JButton("hello"));<br />
    ...<br />
  }<br />
}<br />

Swapping out the findJFrame for a findWindow gives me some sharedframe reference (default JOptionPane root frame?) not the JFrame I'm after. Basically the parent of this events menuitem popupmenu is null - the menuitem itself will have been added as a vanilla jmenubar/jmenu action.

That'll teach me to believe everything I read in a forum ;)

- Richard

PS. Just finishing for alternative ideas

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-11

ehem ... menuitems are "special": they usually reside in a JPopupMenu which has an owner which defines the appropriate parent. Recently, Hans Muller blogged about it (an entertaining and educative read as always)

Looks like WindowUtils.findXX would be a good place to take that pecularity into account. Richard, what do you think?