jkteater
jkteater

Reputation: 1391

minimizing the jframe window with a jbutton click

I know to minimize the jframe, I need to use setExtendedState(JFrame.ICONIFIED);
But what I am trying to figure out is how to get to the frame. This dialog is child of a parent dialog. Here is the Constructor.

    public EdiBaseDialog(EdiDialogHandler edh, Frame parent, TCSession theSession) {
      super(parent, false);
      session = theSession;
      createDialog();
   } 

So when I try to add setExtendedState(JFrame.ICONIFIED) command in my jbutton actionPerformed. Which is in a JPanel Method.

I do not know how to address the frame.

??.setState(JFrame.ICONFIED);

Upvotes: 0

Views: 292

Answers (2)

Durandal
Durandal

Reputation: 20059

What you need to do is go up in the component hierarchy until you arrive at the Frame. There are already helper methods in Swing to do this. Try SwingUtilties:

SwingUtilities.getAncestorOfClass(JFrame.class, this);

(Where 'this' can be any component in the hierarchy) Of course this will only be of use if your dialogs are forming a proper hierarchy (no dialogs using a NULL owner. If thats the case, you have to pass in the Frame through some method or constructor.

Upvotes: 1

Andrew Thompson
Andrew Thompson

Reputation: 168825

Call Dialog.getOwner() from within the dialog.

Upvotes: 2

Related Questions