如何在复选框的帮助下制作JTable editabe?

时间:2016-11-29 07:02:39

标签: java eclipse jtable jcheckbox

我更改了表格模型项目并使表格不可编辑。所以现在,我添加了复选框,以便在用户选择复选框时为用户提供编辑表格的机会。如果未选中该复选框,则表格不可编辑。

这是JTable的代码和复选框。

 JTable jt12;
    String[] column_headers12={"subject","room","time","group"};
    String[][] student_marks12={{"rights","225" ,"10-00","DG-1"},   {"law","302","12-00","MG-5"},{"kazakh","142","14-00","DG-2"},   {"constitution","105","16-20","MG-3"}};
    JScrollPane js12=new JScrollPane();
    js12.setVisible(true);
    js12.setBounds(0, 11, 454, 163);
    panel_12.add(js12);

        jt12=new JTable(student_marks12,column_headers12);
        jt12.setModel(new DefaultTableModel(
            new Object[][] {
                {"rights", "225", "10-00", "DG-1"},
                {"law", "302", "12-00", "MG-5"},
                {"kazakh", "142", "14-00", "DG-2"},
                {"constitution", "105", "16-20", "MG-3"},
            },
            new String[] {
                "subject", "room", "time", "group"
            }
        ) {
            boolean[] columnEditables = new boolean[] {
                false, false, false, false
            };
            public boolean isCellEditable(int row, int column) {
                return columnEditables[column];
            }
        });
        jt12.setFillsViewportHeight(true);
        jt12.setColumnSelectionAllowed(true);
        jt12.setCellSelectionEnabled(true);
        jt12.setBackground(new Color(255, 248, 220));
        js12.setViewportView(jt12); 

        JCheckBox chckbxEditMode = new JCheckBox("edit mode");
        chckbxEditMode.setBackground(new Color(255, 228, 196));
        js12.setRowHeaderView(chckbxEditMode);

0 个答案:

没有答案