1 回答

TA贡献1821条经验 获得超6个赞
找到了答案...天哪,这让我想起了为什么我认为 Java Swing 是 Java 中一个非常蹩脚的领域。
如果您想为应用程序中的每个 JTable 更改它,您可以使用 UIManager 设置下拉线的颜色:
UIManager.put("Table.dropLineColor", Color.cyan);
UIManager.put("Table.dropLineShortColor", Color.cyan);
如果您只想为一张表设置它,那么您必须为您的表设置自定义 UI:
myTable.setUI(new CustomTableUI());
然后,CustomTableUI 确保在 UIManager 中,在绘制线条之前更改 dropLine 的默认颜色。之后,恢复默认值:
private class CustomTableUI extends BasicTableUI {
@Override
public void paint(Graphics g, JComponent c) {
// Store defaults
Color dropLineColor = UIManager.getColor("Table.dropLineColor");
Color dropLineShortColor = UIManager.getColor("Table.dropLineShortColor");
// Set your custom colors here
UIManager.put("Table.dropLineColor", Color.cyan);
UIManager.put("Table.dropLineShortColor", Color.cyan);
// Allow the table to be painted
super.paint(g, c);
// Restore the defaults
UIManager.put("Table.dropLineColor", dropLineColor);
UIManager.put("Table.dropLineShortColor", dropLineShortColor);
}
}
添加回答
举报