Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDialog on top of full screen JFrame disappears

843806Nov 16 2008 — edited Nov 17 2008
I have a problem with a JDialog on top of a full screen JFrame, namely the JDialog kind of disappears when displayed (it bleeds through). I use JRE 1.6.0_03 on Windows. This does not happen under the same version on Linux. I'm attaching the code below.

Test.java:
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Test extends JFrame {
	public Test() {
		final Test frame = this;
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		JButton button = new JButton("Open dialog");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				new TestDialog(frame);
			}
		});
		add(button);
		if (!isDisplayable()) {
			setUndecorated(true);
		}
		pack();
		setVisible(true);
	}
	private static void createAndShowGui() {
		GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
		gd.setFullScreenWindow(new Test());
	}
	public static void main(String[] args) throws Exception {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGui();
			}
		});
	}
}
And TestDialog.java:
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class TestDialog extends JDialog {
	public TestDialog(JFrame frame) {
		super(frame);
		add(new JTextField("test"));
		setModal(true);
		pack();
		setVisible(true);
	}
}
Any ideas why this is happening and how can I solve it? Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2008
Added on Nov 16 2008
3 comments
1,555 views