FlatLaf icon indicating copy to clipboard operation
FlatLaf copied to clipboard

Outline of focus component painted with failure

Open poce1don opened this issue 1 year ago • 3 comments

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.

poce1don avatar Jun 26 '24 02:06 poce1don

Strange 😕 Works fine here.

Do you see the same issue in the FlatLaf Demo?

DevCharly avatar Jun 26 '24 15:06 DevCharly

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);

        });
        
    }

}

poce1don avatar Jun 27 '24 21:06 poce1don

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...

DevCharly avatar Jun 28 '24 10:06 DevCharly

see PR #864

DevCharly avatar Jul 05 '24 21:07 DevCharly

Great, your solution worked perfectly 👍 .

I carried out tests on all the interfaces that had problems, on that damn 😡 1.25x scale, and they were all successful, none failed.

I've been in the Java world for a very short time, about 1.5 years, (compared to your experience), and since I started, I've already decided on desktop development, and when I discovered your FlatLaf library, I was sure to dedicate myself to that, and when I see people with this gigantic knowledge (what I know of yours with Swing, is the best in my opinion), then I ask myself: Will I ever get there? 😕 ... only time will tell, and I know that this time will be very long because I have a lot to learn and master.

Now a question: With your discovery of the flaw in Swing, several modifications to your project were necessary, so wouldn't it also be worth reporting this flaw to Swing support (it would just be one more), or even carrying out the correction ?

poce1don avatar Jul 06 '24 03:07 poce1don