1

To avoid any flickers after JWindow is set to visible I've done it this way - but still I see for a few milliseconds some JLabel (tree: JWindow -> JPanel -> JLabel) old text, then text changes to new value (it must be done before JWindow is set to visible):

public SomeExtendedJWindow extends SomeJWindow {

    @Override
    public void setVisible(boolean visible) {
        if (visible) {
            class doGraphics extends SwingWorker<Void, Object> {

                @Override
                public Void doInBackground() {
                    validate();
                    pack();
                    return null;
                }

                @Override
                protected void done() {
                    SomeJWindow.super.setVisible(true);
                }
            }
            (new doGraphics()).execute();
        } 
    }
}

Maybe I should validate or do something with JLabels also?

Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117
  • 1
    If you want to avoid flicker, you should avoid painting to the window directly, instead paint to something like a JPanel, which is double buffered – MadProgrammer Sep 11 '13 at 06:13
  • Mother idea is to pack the window and position it off the screen somewhere before making it visible, then moving to the visible area of the screen – MadProgrammer Sep 11 '13 at 06:21
  • @MadProgrammer this is common issue, caused by default when you re_use popup container, you can to see, catch previous value after Xxx.setVisible .... – mKorbel Sep 11 '13 at 06:25
  • Tried `someJPanel`, also `someJLabel` to `validate();` - no success.. Maybe I will try to set `JLabel` text to "" right before dialog is closed. – Ernestas Gruodis Sep 11 '13 at 06:26
  • Yes, I'm trying to re-use the window. – Ernestas Gruodis Sep 11 '13 at 06:28
  • don't access swing components off the EDT (as you do by triggering their layout). BTW: same procedure as last time - show a SSCCE that demonstrates the problem, as the flicker is unusual :-) – kleopatra Sep 11 '13 at 06:49
  • I will try somehow to capture it to video, and will see in slow motion what is happening. Do not have such software, will try to find (now leaving the PC). – Ernestas Gruodis Sep 11 '13 at 06:57
  • No need for a video. Post a `SSCCE` so we can run the code ourselves and see exactly what you a doing. – camickr Sep 11 '13 at 15:12
  • I found [here](http://stackoverflow.com/questions/7734277/setvisibletrue-immediate-repaint) the same problem. Is it really impossible to reuse the `JWindow` instead of creating new one? – Ernestas Gruodis Sep 16 '13 at 07:53
  • no, it's not impossible - maybe you are doing something wrong or maybe the problem is highly context dependent: because (until now) nobody can reproduce the flicker with the SSCCE in your other question - not even with the EDT violation that you insist on not fixing ;-) – kleopatra Sep 16 '13 at 10:46
  • OK, my question is - if component is not visible, and I do some changes to it - so the changes applied AFTER the component is set to visible? I mean old graphics is still visible, but gradually repainted with new ones? – Ernestas Gruodis Sep 16 '13 at 15:07

1 Answers1

0

Try it with: jLabel.setText("new text") before make the dialog visible (SomeJWindow.setVisible(true);).

Anyway, it seems not necessary to use a SwingWorker. I would not Override the setVisible(boolean visible).

Just set the text on the Label before call the someExtendedJWindow .setVisible(true).

Bepo
  • 52
  • 8