corretto / corretto-17

Amazon Corretto 17 is a no-cost, multi-platform, production-ready distribution of OpenJDK 17
GNU General Public License v2.0
201 stars 47 forks source link

Visual artifacts with Java Swing #185

Open NadChel opened 3 months ago

NadChel commented 3 months ago

I wrote a simple JSlider using javax.swing, but it's acting weirdly. Here's an MRE:

import javax.swing.SwingUtilities;

public class App {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new MySlider().display());
    }
}
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;

public class MySlider {
    public static final int INITIAL_MEASUREMENT = 50;
    JFrame frame;

    MySlider() {
        this.frame = createFrame();
    }

    private JFrame createFrame() {
        JFrame newFrame = new JFrame("Slider");
        JPanel panel = createPanel();
        newFrame.add(panel);
        newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        newFrame.pack();
        newFrame.setLocationRelativeTo(null); // centers the frame
        return newFrame;
    }

    private JPanel createPanel() {
        JPanel panel = new JPanel();
        panel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
        JLabel label = createLabel();
        JSlider slider = createSlider(label);
        panel.add(slider);
        panel.add(label);
        return panel;
    }

    private JLabel createLabel() {
        return new JLabel(getMeasurementText(INITIAL_MEASUREMENT));
    }

    private static String getMeasurementText(int measurement) {
        return "Measurement: %s".formatted(measurement);
    }

    private JSlider createSlider(JLabel label) {
        JSlider slider = new JSlider(0, 100, INITIAL_MEASUREMENT);
        slider.setPaintTicks(true);
        slider.setMinorTickSpacing(5);
        slider.setPaintTrack(true);
        slider.setMajorTickSpacing(25);
        slider.setPaintLabels(true);
        slider.setSnapToTicks(true);
        slider.addChangeListener(e -> {
            if (e.getSource() == slider) {
                int measurement = slider.getValue();
                label.setText(getMeasurementText(measurement));
            }
        });
        return slider;
    }

    public void display() {
        frame.setVisible(true);
    }
}

It works, but once I move the knob to the left, some unusual ticks appear on the bar itself and then disappear once I release the mouse button. I captured it on the screenshot below

2024-04-04_13-34-41

It's likely to be platform-dependent since it's not easily reproduced elsewhere so here is relevant info

I post this issue to see whether it has to do with the driver or Corretto's compatibility issues with that driver

mrserb commented 2 months ago

Thank you for your report. As a first step, I suggest updating corretto-17 to the latest version just released. If the error is still reproducible, you can check corretto-21 and corretto-22.

I cannot reproduce the problem on my system, so I need some additional information about your desktop: display resolution and scale factor. Do any of these options solve the problem or change the behavior?