1 回答

TA貢獻1821條經(jīng)驗 獲得超6個贊
找到了答案...天哪,這讓我想起了為什么我認為 Java Swing 是 Java 中一個非常蹩腳的領(lǐng)域。
如果您想為應(yīng)用程序中的每個 JTable 更改它,您可以使用 UIManager 設(shè)置下拉線的顏色:
UIManager.put("Table.dropLineColor", Color.cyan);
UIManager.put("Table.dropLineShortColor", Color.cyan);
如果您只想為一張表設(shè)置它,那么您必須為您的表設(shè)置自定義 UI:
myTable.setUI(new CustomTableUI());
然后,CustomTableUI 確保在 UIManager 中,在繪制線條之前更改 dropLine 的默認顏色。之后,恢復(fù)默認值:
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);
}
}
添加回答
舉報