Java 如何更改JSepator的颜色?
问题在标题中 我目前正在做类似的事情:Java 如何更改JSepator的颜色?,java,swing,colors,jseparator,Java,Swing,Colors,Jseparator,问题在标题中 我目前正在做类似的事情: jSperator = new JSeparator(); jSeparator1.setForeground(new java.awt.Color(255, 51, 51)); 但是分隔符保留其默认颜色,如212212212。必须更改'Background',而不是'Foreground' Nimbus外观和感觉的逻辑可能不同 金属L&F import javax.swing.*; import java.awt.*; public class Gr
jSperator = new JSeparator();
jSeparator1.setForeground(new java.awt.Color(255, 51, 51));
但是分隔符保留其默认颜色,如212212212。必须更改
'Background'
,而不是'Foreground'
Nimbus外观和感觉的逻辑可能不同
金属L&F
import javax.swing.*;
import java.awt.*;
public class GridBagSeparator1 {
public static void main(String[] args) {
JFrame frame = new JFrame("Laying Out Components in a Grid");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL);
sep.setBackground(Color.black);
JSeparator sep1 = new JSeparator(SwingConstants.HORIZONTAL);
sep1.setBackground(Color.blue);
JSeparator sep2 = new JSeparator(SwingConstants.HORIZONTAL);
sep2.setBackground(Color.green);
JSeparator sep3 = new JSeparator(SwingConstants.HORIZONTAL);
sep3.setBackground(Color.red);
frame.setLayout(new GridLayout(4, 0));
frame.add(sep);
frame.add(sep1);
frame.add(sep2);
frame.add(sep3);
frame.pack();
frame.setVisible(true);
}
}
JSepator有两种颜色,一种是线条,一种是阴影。 您可以同时更改这两种颜色,分别为背景和前景设置颜色
JSeparator sep = new JSeparator();
sep.setForeground(Color.green); // top line color
sep.setBackground(Color.green.brighter()); // bottom line color
改变背景并不能解决这个问题。我正在使用Matiss,NetbeansGUI构建器在mac上构建界面。也许这是对外观的限制。可能需要使用
UIManager
并更改分隔符。前台
对于Sythetica外观,我必须更改背景并将不透明属性设置为true。