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

JScrollPane Focused Border Bug #876

Closed
poce1don opened this issue Aug 5, 2024 · 4 comments
Closed

JScrollPane Focused Border Bug #876

poce1don opened this issue Aug 5, 2024 · 4 comments
Labels
JDK bug there is something wrong in the JDK

Comments

@poce1don
Copy link

poce1don commented Aug 5, 2024

Karl,

See this bug with the JScrollPane border.

Test 1 Test 2 Test 3
shot1 shot2 shot3

When the rendered cells of the JList are JPanel, the rendered content is "invading" the place intended for the border, only when the scrolling is at the beginning, in other parts, the problem does not occur.

The bug only occurs at 1.25x scale.

If the cells are rendered as standard, the bug does not occur.

The tested FlatLaf versions were 3.5 and 3.6-SNAPSHOT.

Using HiDPIUtils.installHiDPIRepaintManager() also did not solve the bug.

public class ListFail extends JFrame {

    public static void main(String[] args) {

        System.setProperty( "sun.java2d.uiScale", "125%" );

        SwingUtilities.invokeLater(() -> {
            FlatDarkLaf.setup();
            ListFail app = new ListFail();
            app.setVisible(true);
        });

    }

    public ListFail() {
        super("JScrollPane Focused Border Fail");

        String style = "focusedBorderColor: #FF0000;";

        DefaultListModel<String> listModel1 = new DefaultListModel<>();
        JList<String> list1 = new JList<>(listModel1);
        list1.setCellRenderer(new CustomRender());
        JScrollPane scroll1 = new JScrollPane(list1);
        scroll1.putClientProperty(FlatClientProperties.STYLE, style);

        DefaultListModel<String> listModel2 = new DefaultListModel<>();
        JList<String> list2 = new JList<>(listModel2);
        JScrollPane scroll2 = new JScrollPane(list2);
        scroll2.putClientProperty(FlatClientProperties.STYLE, style);

        for ( int i = 0; i < 15; i++ ) {
            listModel1.addElement("Message ID " + i);
            listModel2.addElement("Message ID " + i);
        }

        JPanel panel = new JPanel(new GridLayout(1, 2, 10, 0));
        panel.setBorder(new FlatEmptyBorder(10,10,10,10));
        panel.add(scroll1);
        panel.add(scroll2);

        add(panel, BorderLayout.CENTER);
        setSize(400, 220);
        setLocationRelativeTo(null);

    }

    private static class CustomRender
            extends JPanel
            implements ListCellRenderer<String> {

        private final JLabel lblText;
        private final JPanel pnlContent;

        public CustomRender() {
            super(new BorderLayout());

            lblText = new JLabel();
            pnlContent = new JPanel();
            pnlContent.add(lblText);

            add(pnlContent, BorderLayout.CENTER);
            setBorder(new FlatEmptyBorder(4,4,0,4));
            setBackground(ColorFunctions.shade(UIManager.getColor("List.background"), 0.45f));

        }

        @Override
        public Component getListCellRendererComponent(JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) {

            lblText.setText(value);
            pnlContent.setBackground(isSelected ? UIManager.getColor("List.selectionBackground") : UIManager.getColor("List.background"));

            return this;

        }

    }

}
@DevCharly
Copy link
Collaborator

Seems to be a similar (or same) clipping bug in Swing as described in PR #864.

It is also in Metal and Nimbus L&F (you need to change empty border of panel to 9,10,10,10):

image

image

@DevCharly DevCharly added the JDK bug there is something wrong in the JDK label Aug 5, 2024
@poce1don
Copy link
Author

poce1don commented Aug 5, 2024

This Swing scales part has a lot of bugs on Windows. At least in this case, the solution is simple.
Thanks for the tip! 👍

@poce1don poce1don closed this as completed Aug 5, 2024
@DevCharly
Copy link
Collaborator

... At least in this case, the solution is simple. Thanks for the tip! 👍

And what is the solution 🤔

@poce1don
Copy link
Author

poce1don commented Aug 8, 2024

It is also in Metal and Nimbus L&F (you need to change empty border of panel to 9,10,10,10):

Your tip solved my problem.

Using ScrollPane.viewportBorder also solves this screenshot error, in fact that's what I'm using and the border is being painted without errors at any scale.

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