-1
JTable的渲染是否有任何人知道我可以在這個代碼添加一個複選框:使用複選框
String data[][]={
{"Apple","Banana","Mango"}, {"Apple","Banana","Mango"}, {"Apple","Banana","Mango"}
};
String column[]={"Fruits","Fruits","Fruits"};
table=new JTable(new DefaultTableModel(data, column)){
private Border outside = new MatteBorder(1, 0, 1, 0, Color.RED);
private Border inside = new EmptyBorder(0, 1, 0, 1);
private Border highlight = new CompoundBorder(outside, inside);
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
{
Component c = super.prepareRenderer(renderer, row, column);
JComponent jc = (JComponent)c;
// Add a border to the selected row
if (isRowSelected(row))
jc.setBorder(highlight);
return c;
}
};
jScrollPane1.setViewportView(table);
我只想補充複選框,這樣,如果我選中一個複選框,這將突出和所有選中的複選框會突出顯示。預先感謝您幫助我!
我不明白的問題,所以我會建議你讀了Swing教程[如何使用表(http://docs.oracle.com/javase/tutorial/uiswing/components/table .html)作爲包含複選框的工作示例。 – camickr