如何将 JCheckbox
或 JButton
放在 JTable
的特定行和列上?
最佳答案
不确定按钮,但这是一个放置复选框的工作示例:
import javax.swing.*;
import javax.swing.table.*;
public class Test {
public static void main(String [] args) throws Exception {
DefaultTableModel model = new DefaultTableModel(null, new String [] {"CheckMe", "Value"}) {
public Class getColumnClass(int c) {
switch (c) {
case 0: return Boolean.class;
default: return String.class;
}
} };
JTable table = new JTable(model);
JFrame frame = new JFrame("CheckBox Test");
frame.add(table);
model.addRow(new Object [] {true, "This is true"});
model.addRow(new Object [] {false, "This is false"});
frame.pack(); frame.validate();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
关于java - 如何将 JCheckbox 放在 JTable 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5594639/