Skip to main content

DOCUMENT_MODAL dialog returns focus to wrong JFrame

1 reply [Last post]
jasg
Offline
Joined: 2010-05-20
Points: 0

Hi,
I've got a problem with a document modal dialog.
The situation is as follows, I launch a JFrame (frame1) Then launch another JFrame (frame2).
From frame2, I launch a JDialog as DOCUMENT_MODAL with frame2 set as the owner.

If I launch the dialog, then close it, focus returns to frame2.
However, if I launch the dialog, then click frame1, then return to the dialog and close it, focus returns to frame1, not to frame2 as I would expect.

I've knocked up a quick example to show this behavior.

import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
*
*/
public class FrameTest
{

public static void main(String[] args)
{
final JFrame frame1 = new JFrame("fram 1");
frame1.setMinimumSize(new Dimension(200, 200));
frame1.setLocationRelativeTo(null);
final JFrame frame2 = new JFrame();
JButton button1 = new JButton("button 1");
JButton button2 = new JButton("button 2");
final JDialog dialog1 = new JDialog(frame2, "Dialog");
frame1.add(button1);
frame2.add(button2);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button1.addActionListener(new ActionListener()
{

@Override
public void actionPerformed(ActionEvent e)
{
frame2.setMinimumSize(new Dimension(100, 100));
frame2.setLocationRelativeTo(frame1);
frame2.setVisible(true);
}
});

button2.addActionListener(new ActionListener()
{

@Override
public void actionPerformed(ActionEvent e)
{
dialog1.setMinimumSize(new Dimension(50, 50));
dialog1.setLocationRelativeTo(frame2);
dialog1.setModalityType(ModalityType.DOCUMENT_MODAL);
dialog1.setVisible(true);
}
});

frame1.setVisible(true);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
anthony_p
Offline
Joined: 2006-07-24
Points: 0

This looks like a known issue:

http://bugs.sun.com/view_bug.do?bug_id=6888200