eas之编辑表单元格

--指定表列行单元不可编辑

// 锁定表格、行、列、单元

table.getStyleAttributes().getProtection().setLocked(true);

row.getStyleAttributes().getProtection().setLocked(true);

col.getStyleAttributes().getProtection().setLocked(true);

cell.getStyleAttributes().getProtection().setLocked(true);

 

表头默认是不可编辑的,必须先把Lock关闭。其他操作就和编辑表体一样。

table.getHeadRow().getStyleAttributes().getProtection().setLocked(false);

 

判断指定或者单元格是否允许输入空格,不允许则自动去掉

table.getEditManager().setAllowBlankCharacter (boolean isAllow);

table.getEditManager().isAllowBlankCharacter (boolean isAllow);

 

KDTable的编辑器支持类型绑定和手动绑定两种。

类型绑定即无须指定编辑器,KDTable将根据单元格的值类型,自动绑定到相应的编辑器上。目前内置支持的绑定有(String,JTextField)、(Boolean,JCheckBox)、(Date,KDDatePicker)、(其他类型,JTextField)。数据类型到编辑器的绑定是可扩充的。

手动绑定即用户自己创建编辑器,并绑定到行、列或单元对象上。当编辑器绑定到行、列上时,将应用到行、列上的所有单元格。

手动绑定优先于类型绑定。

// 扩充类型绑定,指定表格中的整型都用指定编辑器编辑

table.putDefaultEditor(Integer.class, yourIntegerEditor);

// 下面的例子演示手动绑定JComboBox类型的编辑器到第三列上

// 创建一个JComboBox JComboBox c = new JComboBox(new String [] {"", "hhh1", "hhh2" , "hhh3"});

// KDTable要求的编辑器必须实现KDTCellEditor接口

// KDTDefaultCellEditor是一个辅助类,可以帮助你将JComboBox转化为KDTable支持的编辑器。KDTDefaultCellEditor cellEditor = new KDTDefaultCellEditor(c);

// 将编辑器绑定到列对象上,此处同样可绑定到行或单元对象table.getColumn(3).setEditor(cellEditor);

 

// 启动编辑,rowIndex和colIndex分别为编辑单元的行列索引。

table.getEditManager().editCellAt(rowIndex, colIndex);

// 结束编辑

table.getEditManager().stopEditing();

// 取消编辑

table.getEditManager().cancelEditing();

posted @ 2019-06-02 18:11  一条有梦想的海洋咸鱼  阅读(523)  评论(0编辑  收藏  举报