JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.18k stars 258 forks source link

Outline of focus component painted with failure #860

Open poce1don opened 1 week ago

poce1don commented 1 week ago

Hi Karl,

See this error that is happening with the outlines in the JScrollPane.

See that in the video the problem does not happen when the scale is at 100% or 150%, but at 125% (my working scale), or 175%, the failure appears.

https://github.com/JFormDesigner/FlatLaf/assets/32749102/e99c1f97-f1b8-446a-af59-58941f33bec9

It doesn't matter the resolution used on the screen, but the scale.

The video screen is my secondary monitor, with 2560x1440 resolution (100% scale). My primary screen is 3840x2160 (125% scale). On both screens, at the mentioned scales, the failure occurs.

In some dimensions where JScrollPane is started, the failure does not occur. In the video, the failures occurred in these specific components, but in JTextField and any other component that displays a border when receiving focus.

Thanks.

DevCharly commented 1 week ago

Strange 😕 Works fine here.

Do you see the same issue in the FlatLaf Demo?

poce1don commented 1 week ago

In the demo, this doesn't happen.

I was thinking it was a flaw with GridLayoutManger (IntelliJ), however, with MigLayout the problem was the same.

The tests went up to the 175% scale, and the interesting thing is that it only happens when it is at 125% or 175%, at 100% and 150% they work perfectly, apparently it has something to do with the 25% increases and not with 50%.

I also thought it could be a bug in the JDK and I tested Jetbrains, Bellsoft (my current one), Adoptium and they all had the same problem, with the difference that in one the failure was not visible as soon as the JFrame was shown, but rather when the JScrollPane received the focus.

With your more than 25 years of experience with Swing, do you suspect what could be causing this?

JDK: Bellsoft Liberica JDK 17.0.10 Windows 10 x64 22H2

import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatLaf;
import net.miginfocom.swing.MigLayout;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.util.Map;

public class LayoutMiglayout extends JFrame {

    public LayoutMiglayout() {
        super("Layout MigLayout");

        var scr1 = new JScrollPane(new JList<String>());
        var pnl1 = new JPanel(new BorderLayout());
        pnl1.add(scr1, BorderLayout.CENTER);

        var scr2 = new JScrollPane(new JList<String>());
        var pnl2 = new JPanel(new BorderLayout());
        pnl2.add(scr2, BorderLayout.CENTER);

        var scr3 = new JScrollPane(new JList<String>());
        var pnl3 = new JPanel(new BorderLayout());
        pnl3.add(scr3, BorderLayout.CENTER);

        var scr4 = new JScrollPane(new JList<String>());
        var pnl4 = new JPanel(new BorderLayout());
        pnl4.add(scr4, BorderLayout.CENTER);

        var pnlContent = new JPanel(new MigLayout("fill, ins 20, wrap 2", "", ""));
        pnlContent.add(pnl1, "grow");
        pnlContent.add(pnl2, "grow");
        pnlContent.add(pnl3, "grow");
        pnlContent.add(pnl4, "grow");

        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setSize(720, 340);
        setLocationRelativeTo(null);
        add(pnlContent);

    }

    public static void main(String[] args) {

        System.setProperty("sun.java2d.uiScale", "1.25x");

        SwingUtilities.invokeLater(() -> {

            FlatLaf.setGlobalExtraDefaults(Map.of(
                    "@accentColor", "#5C50FC",
                    "@background", "#0F0E12",
                    "List.background", "#171621")
            );

            FlatDarkLaf.setup();

            var miglayout = new LayoutMiglayout();
            miglayout.setVisible(true);

        });

    }

}
DevCharly commented 1 week ago

Thanks for the test case. Now I can reproduce it 👍

The problem seems to depend on scrollpane width/heigh. Had to resize the window several times, in small steps, to get the effect:

grafik

Right-top component was previously focused. Right-bottom component is now focused.

I think it is a repaint/scaling bug in Swing. It simply does not repaint 1px on right or bottom side of scroll pane... 😕

This is the same problem as in #582

It is a bug in Swing IMO, but I can implement a workaround 😄 A quick test showed that repainting a 1px larger area fixes the problem for scroll pane and for #582.

However, I think that this problem may also occur in other components that paint to the right/bottom component edge. E.g. text fields, combo boxes, buttons, etc...