首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改JSeparator的颜色?

如何更改JSeparator的颜色?
EN

Stack Overflow用户
提问于 2012-10-26 17:00:51
回答 2查看 11K关注 0票数 8

问题在标题中。

我目前正在做类似这样的事情:

代码语言:javascript
复制
jSperator = new JSeparator();
jSeparator1.setForeground(new java.awt.Color(255, 51, 51));

但分隔符保留其默认颜色,如212、212、212。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-26 17:07:43

我必须更改’Background’而不是’Foreground’

Nimbus Look and Feel的逻辑可能会有所不同

金属L&F

代码语言:javascript
复制
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);
    }
}
票数 13
EN

Stack Overflow用户

发布于 2014-12-30 22:35:57

JSeparator有两种颜色,一种用于线条,一种用于阴影。您可以更改这两种颜色,将颜色分别设置为背景和前景。

代码语言:javascript
复制
JSeparator sep = new JSeparator();
sep.setForeground(Color.green); // top line color
sep.setBackground(Color.green.brighter()); // bottom line color
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13083876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档