swingjtable添加多选框n年没有碰swing开发了 Jtable中加⼀个下checkbox 多选框 这个还真的记录⼀下 ~
import java.awt.BorderLayout;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
public class ChecBoxTest {
public static void main(String[] args) {
JFrame frame = new JFrame("Editable Color Table");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ColorTableModel model = new ColorTableModel();
Vector<Object> rowData = new Vector<Object>();
rowData.add(new Object[] { "1", Boolean.TRUE });
rowData.add(new Object[] { "2", Boolean.TRUE });
rowData.add(new Object[] { "3", Boolean.FALSE });
model.setRowData(rowData);
JTable table = new JTable(model);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(400, 150);
frame.setVisible(true);
}
}
class ColorTableModel extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
private Vector<Object> rowData;
public Vector<Object> getRowData() {
return rowData;
}
public void setRowData(Vector<Object> rowData) {
}
String columnNames[] = { "English", "fdsa" };
public int getColumnCount() {
return columnNames.length;
}
public String getColumnName(int column) {
return columnNames[column];
}
public int getRowCount() {
return rowData.size();
}
public Object getValueAt(int row, int column) {
Object[] obj = (Object[]) (row);
Object[] obj = (Object[]) (row);
return obj[column];
}
html frame
@SuppressWarnings("rawtypes")
public Class getColumnClass(int column) {
return (getValueAt(0, column).getClass());
}
public void setValueAt(Object value, int row, int column) {  Object[] obj = (Object[]) (row);
obj[column] = value;
}
public boolean isCellEditable(int row, int column) {
return (column != 0);
}
}
如何刷新 JTABLE

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。