nat*_*han 7 java swing colors jseparator
问题出在标题中.
我目前正在做类似的事情:
jSperator = new JSeparator();
jSeparator1.setForeground(new java.awt.Color(255, 51, 51));
Run Code Online (Sandbox Code Playgroud)
但分隔符保持默认颜色,如212,212,212.
mKo*_*bel 11
必须改变’Background’而不是’Foreground’
逻辑可能有所不同 Nimbus Look and Feel
金属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);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
JSeparator有2种颜色,一种用于线条,一种用于阴影.您可以分别更改两者,将颜色设置为背景和前景.
JSeparator sep = new JSeparator();
sep.setForeground(Color.green); // top line color
sep.setBackground(Color.green.brighter()); // bottom line color
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9238 次 |
| 最近记录: |