【发布时间】:2015-10-24 15:59:38
【问题描述】:
我正在尝试在基于摇摆的 GUI 中更改 JTable 的背景。我已将表格添加到JScrollPane。但是,没有单元格的表格区域不会改变颜色。我尝试更改滚动窗格的背景和前景色。但是,这也无济于事。我需要编辑 JTable 的哪个组件来更改白色背景。以下是我的部分代码。
public class UiColors {
public static Color BACKGROUND_COLOR_DARK = new Color(30,30,30);
public static Color BACKGROUND_COLOR_LIGHT = new Color(70,70,70);
public static Color GOLDEN_TEXT = new Color(255, 215, 0);
}
JTable 代码
JScrollPane mdScrolPane = new JScrollPane();
mdScrolPane.setBackground(UiColors.BACKGROUND_COLOR_DARK);
mdScrolPane.setOpaque(false);
mdScrolPane.setForeground(UiColors.BACKGROUND_COLOR_DARK);
contentPane.add(mdScrolPane, "cell 1 0 1 5,grow");
mdTableModel = new ReadOnlyTableModel();
for (String col : columnNames) {
mdTableModel.addColumn(col);
}
marketDataTable = new JTable(mdTableModel);
marketDataTable.setFillsViewportHeight(true);
marketDataTable.setToolTipText("Quotes");
marketDataTable.setBorder(null);
marketDataTable.setForeground(new Color(255, 215, 0));
marketDataTable.setBackground(UiColors.BACKGROUND_COLOR_DARK);
marketDataTable.setOpaque(false);
mdScrolPane.setColumnHeaderView(marketDataTable);
mdScrolPane.setViewportView(marketDataTable);
【问题讨论】:
标签: java swing background jtable