Tôi gặp sự cố khi tạo kiểu JScrollPane. Tôi chỉ muốn có thể thay đổi màu của cả ngón cái và nền (và cũng có thể xóa các nút tăng/giảm). Cho đến nay tôi đã cố gắng những điều sau đây:Thay đổi màu ngón tay cái và màu nền của JScrollPane?
this.setBackground(new Color(0,0,0));
this.viewport.setBackground(new Color(0,0,0));
this.getViewport().setBackground(Color.BLACK);
this.setOpaque(false);
this.getVerticalScrollBar().setUI(new BasicScrollBarUI()
{
@Override
protected JButton createDecreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected JButton createIncreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected void configureScrollBarColors(){
}
});
this.getHorizontalScrollBar().setUI(new BasicScrollBarUI()
{
@Override
protected JButton createDecreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected JButton createIncreaseButton(int orientation) {
return createZeroButton();
}
});
}
private JButton createZeroButton() {
JButton jbutton = new JButton();
jbutton.setPreferredSize(new Dimension(0, 0));
jbutton.setMinimumSize(new Dimension(0, 0));
jbutton.setMaximumSize(new Dimension(0, 0));
return jbutton;
}
Cũng
UIManager.put("ScrollBar.trackHighlightForeground", (new Color(57,57,57)));
UIManager.put("scrollbar", (new Color(57,57,57)));
UIManager.put("ScrollBar.thumb", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbHeight", 2);
UIManager.put("ScrollBar.background", (new Color(57,57,57)));
UIManager.put("ScrollBar.thumbDarkShadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbShadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbHighlight", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.trackForeground", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.trackHighlight", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.foreground", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.shadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.highlight", new ColorUIResource(new Color(57,57,57)));
Với tất cả các mã trên tôi nhận được một ngón tay cái tối tăm với một nền trắng. Funnily đủ nếu tôi loại bỏ các chức năng setUI, tôi nhận được một ngón tay cái mặc định với một nền tối ..
Bất kỳ ý tưởng?
Cảm ơn
SOLVED ** * ** *
các configureScrollBarColors chức năng trên có thể được sử dụng theo cách sau:
@Override
protected void configureScrollBarColors(){
this.thumbColor = Color.GREEN;
}
Điều đó thay đổi màu của ngón tay cái thành màu xanh lục.