2

I have a problem where I create two separate JFrames (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 JFrames). 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

Community
  • 1
  • 1
Nick
  • 366
  • 1
  • 4
  • 10
  • 1
    what happens if you parent the JOptionPane to frame1 (or frame2), rather than 'null'? – dashrb Nov 19 '12 at 19:03
  • The 'taskbar' is owned by windows. I don't notice any such odd behavior when I run in java 1.7.0_03 under linux, so I wonder if there is something in your environment. What windows and java versions are you using? – dashrb Nov 19 '12 at 19:06
  • *"I create two separate `JFrames`"* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Nov 20 '12 at 06:53
  • I get the same problem even when I parent the JOptionPane to frame1 or frame2. I'm using Java 1.6.0_24 with Ubuntu 10.04. – Nick Nov 20 '12 at 10:46
  • 1
    Also I appreciate it's not best practice to use two JFrames. But my code is a plugin for a bigger application, and I'm not sure I can actually _get_ to the 'main window' JFrame to use it as a parent. Plus I do actually want my progress updates to be output to a separate window with its own taskbar icon. So I believe I do want two JFrames and neither can be used as parent to my dialog boxes (one I can't get to, the other is an optional progress window so may not exist when the dialog is called). Any ideas about a workaround? Or is there an alternative to a second JFrame for my progress updates? – Nick Nov 20 '12 at 11:05
  • Interestingly I just tried my example on Windows XP using Java 1.6.0_37 and the problem doesn't replicate. I guess that could mean it's an environment problem. (But not necessarily? - ideally my code is suboptimal and can be fixed so that it works on both platforms...) – Nick Nov 20 '12 at 12:20
  • @Nick Did you ever find a solution or workaround for this problem? I'm experiencing it as well on Linux with Java 6. It doesn't seem to happen on Win or with Java > 6. – Dario Seidl Jul 19 '14 at 08:07
  • @Dario Sorry for the delay in replying. No, I never did find a solution or workaround; I decided that it was irritating but not worth any more time to fix for the project I was working on at the time. If you have found a solution since you commented it would be interesting to hear it... – Nick May 02 '15 at 09:00

2 Answers2

1

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

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Sorry, I don't find this answer at all useful - I'm not sure that it really addresses my question. I understand that a JOptionPane will pause code execution until the dialog is dismissed, and that it blocks keyboard and mouse events. But I don't see why this would cause strange effects to the taskbar icons (effects that persist when the dialog is closed). Could you explain more clearly what I have done wrong? – Nick Nov 20 '12 at 11:15
0

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.

matheuslf
  • 309
  • 1
  • 9
  • The icon does disappear and stays disappeared even when the dialog box is closed... – Nick Nov 20 '12 at 11:07