swing JTable with ScrollBar - color of square between headers and track

荒凉一梦 提交于 2019-12-24 00:01:02

问题


I have a JTable with BasicScrollBarUI, I set the headers background color: table.getTableHeader().setBackground(GuiConstants.backgroundColor);

and the scrolbar background color: public class ScrollBarUI extends BasicScrollBarUI {

@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
    c.setBackground(GuiConstants.backgroundColor);

}

}

I still have a square between them that its color won't change. does anybody knows how to change it also to their color?

thanks


回答1:


As shown in How to Use Scroll Panes: Providing Custom Decorations, you can use the scroll pane's setCorner() method to add a colored Component:

JPanel panel = new JPanel();
panel.setBackground(Color.gray);
scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, panel);

You may have to set the panel's opacity to true, and you may want to select a suitable color from the the current Look & Feel using the UIMnager.



来源:https://stackoverflow.com/questions/25708734/swing-jtable-with-scrollbar-color-of-square-between-headers-and-track

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!