![]()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.icon-blank {
background: url('icons/blank.gif') no-repeat center center
}
.icon-add {
background: url('icons/edit_add.png') no-repeat center center
}
.icon-edit {
background: url('icons/pencil.png') no-repeat center center
}
你可以实现一个 TableCellRendererclass MyTableCellRenderer implements TableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
//根据特定的单元拿旅格设置不同的Renderer,假如你要在第2行第3列显示图标消洞凳颤枝
if(row == 1 &&column == 2) {
ImageIcon icon = new ImageIcon("icon的位置")
JLabel label = new JLabel(icon)
label.setOpaque(false)
return label
} else {
......
......
}
}
然后把这个Renderer设置到第一列上
TableCellRenderer myRenderer = new MyTableCellRenderer()
table.getColumnModel.getColumn(2).setCellRenderer(myRenderer)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)