无法在我的自定义jdialog

时间:2019-06-24 14:11:14

标签: java swing user-interface jseparator

我在自定义jdialog中使用JSeparator

这是我的代码:

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

我希望分隔符的颜色应该是(0,0,51),但是分隔符会保留其默认颜色,例如(212,212,212)。

1 个答案:

答案 0 :(得分:0)

发生这种情况是因为我忘记在课堂上设置Look-and-Feel

感谢@SergiyMedvynskyy