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

Outline of focus component painted with failure #860

Closed
poce1don opened this issue Jun 26, 2024 · 5 comments
Closed

Outline of focus component painted with failure #860

poce1don opened this issue Jun 26, 2024 · 5 comments
Milestone

Comments

@poce1don
Copy link

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.

borderFail.mp4

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
Copy link
Collaborator

Strange 😕
Works fine here.

Do you see the same issue in the FlatLaf Demo?

@poce1don
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Collaborator

see PR #864

@poce1don
Copy link
Author

poce1don commented Jul 6, 2024

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 poce1don closed this as completed Jul 9, 2024
DevCharly added a commit that referenced this issue Jul 10, 2024
…mponent paintings at 125% or 175% scaling on Windows (issues #860 and #582)
@DevCharly DevCharly added this to the 3.5 milestone Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants