第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java:如何更改 JTable 拖放線顏色?

Java:如何更改 JTable 拖放線顏色?

MMTTMM 2023-08-16 16:33:25
我目前正在嘗試在具有高度定制的 UI 的 JTable 中啟用拖放功能。當對表行進行拖放事件時,將在該行被拖放的位置出現(xiàn)一條線(這條線是由 Java 繪制的)。我目前正在嘗試弄清楚如何更改該目標線/下降線的顏色,但我不確定如何做到這一點。誰能指出我該往哪里看的正確方向,或者我該如何做到這一點?下面是 JTable 的屏幕截圖。由于某種原因,我的光標沒有在屏幕截圖中捕獲,但我放置光標的單元格是以我想要的線條顏色繪制的。對于最左邊的單元格和最右邊的單元格,某些單元格的顏色原因是藍色的。
查看完整描述

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);

    }


}


查看完整回答
反對 回復(fù) 2023-08-16
  • 1 回答
  • 0 關(guān)注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號