JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:請問一個 isCellEditable 修改後的問題 [Re:gene]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2004-05-10 21:49 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
gene wrote:
... 恕刪]
後, 竟發現顯現出來的jtable從畫面1,變成畫面2,我知道這是
因為該cell處於edit mode所致,但是底色變成白色好像怪怪的,
有沒有辦法讓選取的那一整列資料變成原來畫面一,感恩啦!


這是有理由的, 在 selection mode, 可以讓 user 很明顯的知道那一個 cell 有 focus, and when press a key, he/she goes to edit mode on that cell.
Edit mode 當然是白底, 就如 JTextField.
您要分開 selection mode and edit mode.
If you like when user edit, the background change to the color as you like, then create your own TableCellEditor (or customize the default one)
If you like when user do selection, the background change to the color as you like, (I think that is what you want) then there are 2 ways:
(1) Create your own TableCellRenderer (or customize the default one)
(2) Change the default settings.

Here is a quick demo to show you the (2) Change the default setting technic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import javax.swing.*;
 
public class Test {
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put("Table.focusCellBackground", defaults.get("Table.selectionBackground"));
            defaults.put("Table.focusCellForeground", defaults.get("Table.selectionForeground"));
        } catch (Exception e) { e.printStackTrace(); }
                    
        JTable table = new JTable(5,5) {
            public boolean isCellEditable(int row, int col) { return true; }
        }; // This is just for demo, normally, we do not need create inner class.
           // Because, by default, the JTable.isCellEditable(row, col) will return true.
           
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(new JScrollPane(table));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}

Swing 很容易的讓您改造, 您可以改成任何您想要的結果...
不過 GUI design 不只是好不好看而已, 還有很多因素要考慮哦 !


T55555 edited on 2004-05-13 12:07
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
2134 請問一個 isCellEditable 修改後的問題 gene 281 2004-05-09 17:26
3345 Re:請問一個 isCellEditable 修改後的問題 T55555 1970 2004-05-10 21:49
1787 Re:請問一個 isCellEditable 修改後的問題 gene 74 2004-05-11 22:46
» JWorld@TW »  Java SE 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8