RFR: 8224261: JProgressBar always with border painted around it [v3]

Alexey Ivanov aivanov at openjdk.org
Tue Nov 21 14:37:25 UTC 2023


On Tue, 21 Nov 2023 08:37:45 GMT, Abhishek Kumar <abhiscxk at openjdk.org> wrote:

> `boolean` variable is changed to local variable. Others are used in EDT and other method, so kept it as class variables.

Do they need to be? I mean you can do everything on EDT, even throw the exception from there. It could something like this:


public class TestProgressBarBorder {
    public static void main(String[] args) throws Exception {
        for (UIManager.LookAndFeelInfo laf :
                UIManager.getInstalledLookAndFeels()) {
            if (!laf.getName().contains("Nimbus") && !laf.getName().contains("GTK")) {
                continue;
            }
            System.out.println("Testing LAF: " + laf.getName());
            SwingUtilities.invokeAndWait(() -> test(laf));
        }
    }

    private static void test(UIManager.LookAndFeelInfo laf) {
        setLookAndFeel(laf);

        JProgressBar progressBar = createProgressBar();
        progressBar.setBorderPainted(true);
        BufferedImage withBorder = paintToImage(progressBar);
        progressBar.setBorderPainted(false);
        BufferedImage withoutBorder = paintToImage(progressBar);

        boolean equal = Util.compareBufferedImages(withBorder, withoutBorder);
        if (equal) {
            try {
                ImageIO.write(withBorder, "png", new File("withBorder.png"));
                ImageIO.write(withoutBorder, "png", new File("withoutBorder.png"));
            } catch (IOException ignored) {}
            throw new RuntimeException("JProgressBar border is painted when border\n" +
                                       " painting is set to false");
        }
    }

    private static JProgressBar createProgressBar() {
        JProgressBar progressBar = new JProgressBar();
        progressBar.setSize(100, 50);
        progressBar.setValue(0);
        progressBar.setStringPainted(true);
        return progressBar;
    }


Because the exception is thrown from EDT, the exception thrown from main is `InvocationTargetException`, yet the CI will still show you the cause. If you want to avoid it, you can return the boolean value from the `test` method.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16467#discussion_r1400695948


More information about the client-libs-dev mailing list