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

Default JPanel rendered unstyled in JOptionPane #761

Closed
ArthurKwasny opened this issue Nov 11, 2023 · 1 comment
Closed

Default JPanel rendered unstyled in JOptionPane #761

ArthurKwasny opened this issue Nov 11, 2023 · 1 comment
Milestone

Comments

@ArthurKwasny
Copy link

The default JPanel from the javax.swing package won't render with its applied style, if it is displayed in a JOptionPane / JDialog (magenta / red panel).
If using an anonymous or named sub class of JPanel, the panel will be rendered without any issues (green / blue panel).

In a JFrame all panels are rendered as expected (top window):
image

It does not matter, how styling is applied, e.g. setting background via JPanel.setBackground(Color) will also not render the correct background color.

Tested with FlatLaf 3.2.5, Adoptium JDK 21 on Windows 10.

Test code:

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLightLaf;

public class OptionPaneBug {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            FlatLightLaf.setup();

            // correct rendering:
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            frame.setContentPane(createPanel());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);

            // fails to render main / r panel with its applied style:
            JOptionPane.showMessageDialog(frame, createPanel());
        });
    }

    static JPanel createPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.MAGENTA);

        // default class
        JPanel r = new JPanel();
        r.putClientProperty(FlatClientProperties.STYLE,
                "background: #ff0000; border: 12,12,12,12;");
        panel.add(r);

        // anonymous sub class
        JPanel g = new JPanel() {};
        g.putClientProperty(FlatClientProperties.STYLE,
                "background: #00ff00; border: 12,12,12,12;");
        panel.add(g);

        // named sub class
        JPanel b = new TestPanel();
        b.putClientProperty(FlatClientProperties.STYLE,
                "background: #0000ff; border: 12,12,12,12;");
        panel.add(b);

        return panel;
    }
}

and

public class TestPanel extends javax.swing.JPanel {}
@DevCharly DevCharly changed the title Default JPanel rendered unstyled in JDialog Default JPanel rendered unstyled in JOptionPane Nov 14, 2023
@DevCharly
Copy link
Collaborator

This affects only JOptionPane (but not JDialog).

fixed in latest 3.3-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

Thanks for reporting

@DevCharly DevCharly added this to the 3.3 milestone Nov 14, 2023
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