Access Keys:
Skip to content (Access Key - 0)
compared with
Current by Olivier Catteau
on Dec 26, 2009 18:11.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (13)

View Page History
{section}
{column:width=10%}
!http://www.stateofmind.fr/images/swing.jpg!
{column}
{column:width=2%}
{column}
{column:width=88%}
h3. Cette page présente une série de trucs et astuces relatifs au composant JTable.
{column}
{section}
{section}
{column:width=50%}
h24. Preventing the current cell move down after pressing enter
{code:controls=true}
table.getActionMap().put("selectNextRowCell", new AbstractAction(){
public void actionPerformed(ActionEvent e){}


h24. Terminate edit on focus lost
The client property "terminateEditOnFocusLost" defines what to do when the focus goes outside of a JTable. This property is of type Boolean.
If this property is set, then it tries to commit the changes in the editor. If it can't be committed then the changes are cancelled.
If the value of this property is null, the default value is Boolean.FALSE. So, this feature is disabled by default in a JTable. To enable this feature, you have to set this property on your JTable such like this :
{code:controls=true}
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
{code}
{column}
{column:width=1}
{column}
{column:width=50%}
h24. Preventing editing of cell when a key is typed
The client property "JTable.autoStartsEdit" defines what to do when a key is pressed when the cursor is on a JTable cell. This property is of type Boolean.
If the property is set to Boolean.TRUE, then the cell will start the edit mode when a key is pressed. If the value of this property is null, the default value is Boolean.TRUE. So, this feature is enabled by default in a JTable. To disable this feature, you have to set this property on your JTable such like this :
{code:controls=true}
table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
{code}


h24. Grayout a non editable cell
If you don't want to change every TableCellRenderer of the JTable or if you simply can't do it, the easy way to grayout a non editable JTable cell is the following way :
{code:controls=true}
JTable table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
};
{code}
{column}
{section}
Adaptavist Theme Builder (4.0.3) Atlassian Confluence 3.2.1_01, the Enterprise Wiki: Intranet software for documentation and knowledge management