您可以在下图中看到我的应用程序的一部分。基本上JFrame
包含其他内容:JTable
中的JScrollPane
。
我在两个元素上设置背景颜色(参见A),但在哪里可以设置箭头B的颜色?
声明如下:
公共类CXPanel扩展JPanel { private JTablet_ao = new JTable(ViewsModelService.getCXTableModel(0));
public CXPanel() {
GridBagConstraints c = new GridBagConstraints();
(...)
this.add(new CXSubPanel(), c);
}
public class CXSubPanel extends GamePanel {
public CXSubPanel() {
super(new GridLayout(3, 0, 0, 0));
TableScrollPane sc_ao = new TableScrollPane();
(... adding JTable to scrollpane ect...)
this.add(sc_ao);
}
}
}
为每个面板scrollpane
(及其viewport
)单元格和表格的标题渲染器设置背景颜色,标题渲染器的示例:
public class CXHeaderRenderer extends JLabel implements TableCellRenderer {
public CXHeaderRenderer() {
this.setFont(ViewsPreferences.CX_HEADER_FONT);
this.setForeground(ViewsPreferences.CX_HEADER_COLOR);
this.setBackground(ViewsPreferences.CX_HEADER_BACKGROUND);
this.setOpaque(true);
this.setBorder(null);
this.setHorizontalAlignment( JLabel.CENTER );
this.setPreferredSize(new Dimension(ViewsPreferences.P_HEADER_WIDTH, ViewsPreferences.P_HEADER_HEIGHT));
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
setText(value.toString());
return this;
}
}