如何更改JSplitPane分隔线的颜色或背景色? [英] How to change the color or background color of JSplitPane divider?

查看:733
本文介绍了如何更改JSplitPane分隔线的颜色或背景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为JSplitPane分隔线设置背景色.我已经编写了以下代码,但是似乎没有用.

I am trying to the set the background color for the JSplitPane divider. I've written the following code, but it doesn't seem to work.

        BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI();
        BasicSplitPaneDivider divider = ui.getDivider();
        divider.setBackground(Color.decode("#FFFACD"));

我什至尝试了这里给出的建议 如何在JSplitPane中将BackGround颜色设置为分色器

I've even tried the suggestion given here How to set BackGround color to a divider in JSplitPane

有人可以指出错误或让我知道其他方法吗?

Can someone please point out the mistake or let me know any other approach?

推荐答案

这对我有用

BasicSplitPaneDivider divider = (BasicSplitPaneDivider) splitPane.getComponent(2);
divider.setBackground(Color.black);
divider.setBorder(null);

这篇关于如何更改JSplitPane分隔线的颜色或背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆