javaswinguser-interfacejseparator

Unable to change background-foreground color of jseparator in my custom jdialog


I am using a JSeparator in my custom jdialog

This is my code:

public class CheckDialog extends javax.swing.JDialog {
    private boolean setuju =false;

    public CheckDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        JSeparator jSeparator4 = new JSeparator(SwingConstants.HORIZONTAL);
        JSeparator jSeparator6 = new JSeparator(SwingConstants.HORIZONTAL);
        JSeparator jSeparator7 = new JSeparator(SwingConstants.HORIZONTAL);
        jSeparator4.setBackground(new java.awt.Color(0, 0, 51));
        jSeparator4.setForeground(new java.awt.Color(0, 0, 51));
        jPanel2.add(jSeparator4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 280, 10));
        jSeparator6.setBackground(new java.awt.Color(0, 0, 51));
        jSeparator6.setForeground(new java.awt.Color(0, 0, 51));
        jPanel10.add(jSeparator6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 40, 10));
        jSeparator7.setBackground(new java.awt.Color(0, 0, 51));
        jSeparator7.setForeground(new java.awt.Color(0, 0, 51));
        jPanel1.add(jSeparator7, new   org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 110, 10));
    }

    public boolean showDialog() {
        this.setUndecorated(true);
        this.pack();
        this.setBackground(new Color(0,0,0,0));
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        return setuju;
    }
}

my result

I expect the separator color should be (0, 0, 51) but separator keeps its default color, something like (212, 212, 212).


Solution

  • this is happened because i forgot to set the Look-and-Feel in my class

    thanks to @SergiyMedvynskyy