is it possible to make Java Swing activate the parent JFrame, when closing a document modal JDialog ? The default mechanisms seems to activate the last JFrame instead of the parent JFrame. This may confuse users.
Here is some sample code to reproduce the problem:
1: Press the button "step 1: press this"
2: Press the button "step 2: press this"
3: Bring the JFrame to front with the title "step 3: activate this"
4: Close the JDialog with the title "step 4: close this"
=> now, the JFrame with the text "frame 1" should go to front.
=> instead, the JFrame with the text "step 3: activate this" goes to front.
=> for users, this is confusing, because the closed JDialog is document modal to frame 1
public static void main(String[] args) {
final JFrame f1 = new JFrame("frame 1");
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setLayout(new FlowLayout());
f1.add(new JButton(new AbstractAction("step 1: press this") {
@Override
public void actionPerformed(ActionEvent e) {
JFrame f2 = new JFrame("step 3: activate this");
f2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f2.setLayout(new FlowLayout());
f2.add(new JLabel("step 3: activate this"));
f2.pack();
f2.setVisible(true);
}
}));
f1.add(new JButton(new AbstractAction("step 2: press this") {
@Override
public void actionPerformed(ActionEvent e) {
JDialog d = new JDialog(f1, "step 4: close this", ModalityType.DOCUMENT_MODAL);
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
d.setLayout(new FlowLayout());
d.add(new JLabel("step 4: close this"));
d.pack();
d.setVisible(true);
}
}));
f1.pack();
f1.setVisible(true);
}
Any ideas ? (I dont want do call f1.toFront() manually, because the results in a short "flickering" of the windows)
Best regards Marcel