Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repaint issue with JDK 19 or higher #700

Closed
ArthurKwasny opened this issue Jul 19, 2023 · 9 comments
Closed

Repaint issue with JDK 19 or higher #700

ArthurKwasny opened this issue Jul 19, 2023 · 9 comments
Labels
JDK bug there is something wrong in the JDK

Comments

@ArthurKwasny
Copy link

There is a bug with JDK >= 19 and FlatLaf 3.x which causes panels to be repainted without repainting all/several child components under certain circumstances. This does not happen with Swings default Laf or with JDK 18.

This issue can be reproduced by locking and unlocking the PC. It also happens while previewing files within the Windows file explorer, eg with preview handlers from MS PowerToys.

Here: #592 "flatlaf.useWindowDecorations" was mentioned and first I thought it might be related, but I can still reproduce this bug pretty consistently, regardless of this setting.

Steps to reproduce:

  • Execute FlatLaf demo jar with JDK 19 or higher
  • Lock the session (Win + L)
  • Unlock the session
  • If all components are still visible, they disappear after clicking on one of them

It looks like only options of OptionPanes are rendered reliably.
Before the unlock:
image
After the unlock:
image

Tested on two Windows 10 machines with Oracles OpenJDK 19, Adoptium JDK 18 (no issues) / 19 / 20 and a simple maven project as well as the FlatLaf demo jar (v3.0, v3.1.1).

Test code I used:

import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.WindowConstants;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatDarkLaf;

public class RepaintBug {

    public static void main(String[] args) {
        System.setProperty("flatlaf.useWindowDecorations", "false");
        FlatDarkLaf.setup();

        EventQueue.invokeLater(() -> {
            JFrame frame = new JFrame("Test");
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            JPanel panel = new JPanel();
            frame.getContentPane().add(panel);
            panel.add(new JButton("btn"));
            panel.add(new JLabel("lbl"));
            panel.add(new JTextArea("area"));
            JComboBox<Object> box = new JComboBox<>();
            JToolBar toolbar = new JToolBar();
            toolbar.add(new JButton("T"));
            toolbar.add(new JButton("C"));
            box.setEditable(true);
            JTextField editor = (JTextField) box.getEditor().getEditorComponent();
            editor.putClientProperty(FlatClientProperties.TEXT_FIELD_TRAILING_COMPONENT, toolbar);
            panel.add(box);

            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        });
    }
}
@DevCharly
Copy link
Collaborator

That's strange 😕

Probably a general Java/Swing issue.
I have the same problem with Windows L&F, Nimbus and Metal.
Sometimes it is necessary to lock and unlock twice to get the effect.
I'm on Windows 11.

image

When resizing the window, all components are shown again:

image

Seems that some kind of image buffer is cleared on lock/unlock session...

@DevCharly
Copy link
Collaborator

It is a JDK bug: https://bugs.openjdk.org/browse/JDK-8298876

Fix is coming with Java 21.
Just tried Java 21 EA build 31 from here https://jdk.java.net/21/ and it works.

Seems that we should avoid using Java 19 or 20 for Swing applications 😒

@ArthurKwasny
Copy link
Author

Ah, great to hear that it is already fixed in the next release, thanks for looking that up! 😁

I might have found a similar issue which is related to the window decorations setting but not to the JDK version.
If enabled and a window with a minimum size of 0,0 is resized to its minimum size, the rendering will be broken afterwards (in the demo jar it often requires a click on one of the tabs to show its effect):
image
But disabling / re-enabling window decorations fixes it.

@DevCharly
Copy link
Collaborator

Can not reproduce the second issue.

a window with a minimum size of 0,0 is resized to its minimum size

How to do that?

Could you give us detailed steps to reproduce? Thx.

@ArthurKwasny
Copy link
Author

ArthurKwasny commented Jul 20, 2023

Just drag the window by the edge to its minimum size, so only the title and the top right buttons are displayed:
image

But it looks like it only occurs when a JTabbedPane is somewhere in the content pane.

Steps to reproduce:

  • Start the FlatLaf demo jar
  • resize it to its minimum size
  • resize to a bigger size
  • switch to a different tab inside a JTabbedPane, eg 'More components' in the demo jar

It looks like the JFrame content panel is also rendering the JTabbedPanes selected content panel

Additional test code:

import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.WindowConstants;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatDarkLaf;

public class RepaintBug {

    public static void main(String[] args) {
        FlatDarkLaf.setup();

        EventQueue.invokeLater(() -> {
            JFrame frame = new JFrame("Test");
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            JTabbedPane tabbedPane = new JTabbedPane();
            frame.getContentPane().add(tabbedPane);
            for (int i = 0; i < 2; i++) {
                JPanel panel = new JPanel();
                tabbedPane.add(panel, i);
                panel.add(new JButton("btn"));
                panel.add(new JLabel("lbl"));
                panel.add(new JTextArea("area"));
                JComboBox<Object> box = new JComboBox<>();
                JToolBar toolbar = new JToolBar();
                toolbar.add(new JButton("T"));
                toolbar.add(new JButton("C"));
                box.setEditable(true);
                JTextField editor = (JTextField) box.getEditor().getEditorComponent();
                editor.putClientProperty(FlatClientProperties.TEXT_FIELD_TRAILING_COMPONENT, toolbar);
                panel.add(box);
            }

            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        });
    }
}

@DevCharly
Copy link
Collaborator

@ArthurKwasny finally found the cause for the issue that you reported here: #700 (comment)

fixed in latest 3.3-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

Please try it out.

@DevCharly DevCharly added the JDK bug there is something wrong in the JDK label Nov 25, 2023
@ArthurKwasny
Copy link
Author

@DevCharly That's great, but it seems to work only partially.

I am still able to replicate this repaint issue by doing the following steps:

  • run the test code
  • Resize test window to minimum size
  • Resize test window to a bigger size
  • switch focus to a different application
  • switch focus back to test window
    Sometimes it is necessary to repeat the last two steps or click on the test buttons / input field.

Tested with flatlaf-3.3-20231125.181807-21.jar. on Windows 10, Adoptium JDK 21+35.

@DevCharly
Copy link
Collaborator

@ArthurKwasny can not reproduce. Can you post some screenshot or screen cast?

@ArthurKwasny
Copy link
Author

@DevCharly That's unfortunate :/ I recorded the issue:

Video.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JDK bug there is something wrong in the JDK
Projects
None yet
Development

No branches or pull requests

2 participants