我有一个带有 JScrollPane
的文本区域,并且正在使用以下内容定制显示;
JTextArea text = new JTextArea();
text.setOpaque(false);
text.setFont(...);
text.setForeground(Color.white);
text.setBackground(Color.black);
JScrollPane scroll = new JScrollPane(text);
scroll.setOpaque(false);
scroll.getViewport().setOpaque(false);
并且滚动和文本区域显示为透明(非不透明),但是,我似乎无法影响实际的滚动条。 它们仍然显示为默认的灰色,我想更改它们的颜色和/或使它们透明以匹配其余部分。
我尝试过类似的事情
scroll.setBackground(Color.black);
scroll.getVerticalScrollBar().setOpaque(false);
但这没有任何区别。
自定义滚动条显示的首选方式是什么?
最佳答案
and the scroll and text area are showing as transparent (non-opaque), however, I can't seem to affect the actual scroll bars. They still appear as the default grey color where I'd like to change their color and/or make them transparent to match the rest.
有两种方法
您需要重写
BasicScrollBarUI()
,只有
VerticalScrollBar
,您需要重写并添加HorizontalScrollBar
到ScrollPaneLayout()
,返回Horizontal JScrollBar
的坐标,
关于java - JScrollPane实际滚动条的自定义显示(设为透明),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18181964/