通过单击确定列避免选择JTable行

时间:2013-11-15 14:31:11

标签: java jtable selection

我想点击JTable行。单击任何行(column.index=0)的第一列,将突出显示该行。单击行中的任何其他列不应突出显示该行。我怎么能意识到这一点呢?

1 个答案:

答案 0 :(得分:0)

// Sry - 编辑工具的问题

公共类JTableTest扩展了javax.swing.JFrame {

public JTableTest() {
    initComponents();
}

private void initComponents() {
    jButton1 = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTable1 = new javax.swing.JTable();

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    jButton1.setText("jButton1");
    getContentPane().add(jButton1, java.awt.BorderLayout.SOUTH);

    jTable1.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {
            {"click will select", null},
            {"click will select", null},
            {"click will select", null},
            {"click will select", null}
        },
        new String [] {
            "String", "Boolean"
        }
    ) {
        Class[] types = new Class [] {
            java.lang.String.class, java.lang.Boolean.class
        };

        public Class getColumnClass(int columnIndex) {
            return types [columnIndex];
        }
    });
    jScrollPane1.setViewportView(jTable1);

    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

    pack();
}

public static void main(String args[]) {
    new JTableTest().setVisible(true);
}

private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;

}