princemaozh
发贴: 7
积分: 0
|
于 2006-03-31 15:07
liuzhenke15, 你的JTable行为友好多了。有点象EXCEL表格的行为。
我尝试用了你的方法。单击cell的时候,仍能进入编辑。代码如下: String[][] BookInfo = { {"JAVA","james","one"}, {"SQL","jacky","two"} }; String [] ColumnName = {"Col1","Col2","Col3"}; DefaultTableModel dm = new DefaultTableModel(); dm.setDataVector(BookInfo,ColumnName); JTable table = new JTable( dm ); table.addKeyListener(new CTableKeyAdapter(table)); TableCellEditor tableCellEditor=table.getDefaultEditor(String.class); if (tableCellEditor!=null) { if (tableCellEditor instanceof DefaultCellEditor) { ((DefaultCellEditor)tableCellEditor).setClickCountToStart(2); } }
而我期望单击时禁止编辑,双击时才允许编辑。如何实现呢?
|