Hey all,
I've run into a quirk with JDialogs on a Linux desktop (with multiple workspaces), and I'm wondering if there's a "solution" or if I'm just looking at it the wrong way. Anyway:
Background on what I mean by workspace: I'm running Red Hat Linux with a workspace switcher, which is basically a little button that lets me switch between different desktops. I can move windows from one workspace to another by right-clicking the window title bar and selecting "move to workspace X".
The setup: I have a JFrame with a child JDialog whose visibility can be toggled by a button on the JFrame. That works fine as long as both the JFrame and the JDialog are both on the same workspace.
The problem: But if I move the JDialog to a different workspace (moving the JFrame brings the JDialog with it), the JFrame can no longer set the visibility of the JDialog to false. Pressing the button on the JFrame should hide the JDialog, but the JDialog remains open on whatever workspace I put it. Furthermore, the JDialog stays open no matter what, even if I manually switch to that workspace and then press the X close button on the JDialog title bar.
The SSCCE:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class OneDialogTest{
JDialog dialog;
JFrame frame;
public OneDialogTest(String name){
frame = new JFrame("frame: " + name);
frame.setSize(200,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
frame.setLocation(100, 100);
dialog = new JDialog(frame, "dialog: " + name, false);
dialog.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
dialog.setSize(200,50);
dialog.setLocation(100, 50);
JButton toggleMyButton = new JButton("toggle my dialog");
toggleMyButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
toggleDialog();
}
});
frame.add(toggleMyButton);
frame.setVisible(true);
dialog.setVisible(true);
}
public void toggleDialog(){
dialog.setVisible(!dialog.isVisible());
}
public static void main(String [] args){
OneDialogTest test = new OneDialogTest("one");
}
}
But I don't see a problem, you'll probably say: On a single workspace, this will work fine. But if I put the JDialog on a different workspace than the parent JFrame, the JFrame seems to lose control over the JDialog.
Thanks for your time, I appreciate anybody's help. I'm curious to see what's going on here!