Reputation: 366
I have a problem where I create two separate JFrame
s (one is my main application, the other shows task progress using console output...).
However, subsequently bringing up a dialog box has a strange effect on the two taskbar icons (i.e. for the JFrame
s). Namely it causes one taskbar icon to disappear, although both windows still exist. Note that the missing taskbar icon can be "restored" by minimising or maximising the corresponding window.
The following example code generates the problem:
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class taskbarExample {
private static JFrame frame1;
private static JFrame frame2;
public static void main (String[] args) {
frame1 = new JFrame("Frame 1");
frame1.setSize(200,600);
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame1.setVisible(true);
frame2 = new JFrame("Frame 2");
frame2.setSize(600,200);
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame2.setVisible(true);
JOptionPane.showMessageDialog(null, "Dialog box");
}
}
For comparison, try commenting out the JOptionPane
line... results in no problems.
Can anyone explain what is going on here? I have seen a previous question referring to a similar problem, but without example code and no answer that helped me. Found here
Upvotes: 2
Views: 1023
Reputation: 309
The showMessageDialog brings up an information-message dialog. The first parameters determines the Frame in which the dialog is displayed. if null, or if the parentComponent has no Frame, a default Frame is used.
When this function (showMessageDialog) is started the mouse and keyboard is blocked until you close the dialog information.
This effect is natural and does not mean that icon disappeared.
Upvotes: 0
Reputation: 109823
This is basic property, JOptionPane
blocked code executions untill is visible on the screen,
this container is Modal and locking for mouse and keyboeard event outside of JOptionPane bounds
Upvotes: 1