The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.table  [62 examples] > Editing  [8 examples]

e955. Setting the Activation Click Count for a Table Cell Editor in a JTable Component

By default, a table cell editor is activated with a double-click. The activation behavior is controlled by the renderer, not by a table property. To change this, override the isCellEditable() method of the editor. See e953 Creating a Custom Table Cell Editor in a JTable Component for more information about table cell editors.
    
    public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor {
        // See e953 Creating a Custom Table Cell Editor in a JTable Component
        // for other methods that need to be implemented.
    
        public boolean isCellEditable(EventObject evt) {
            if (evt instanceof MouseEvent) {
                int clickCount;
    
                // For single-click activation
                clickCount = 1;
    
                // For double-click activation
                clickCount = 2;
    
                // For triple-click activation
                clickCount = 3;
    
                return ((MouseEvent)evt).getClickCount() >= clickCount;
            }
            return true;
        }
    }

 Related Examples
e953. Creating a Custom Table Cell Editor in a JTable Component
e954. Preventing Invalid Values in a Cell in a JTable Component
e956. Programmatically Starting and Stopping Cell Editing in a JTable Component
e957. Creating a Text Field That Mirrors the Value in the Anchor Cell in a JTable Component
e958. Disabling User Edits in a JTable Component
e959. Using a JComboBox in a Cell in a JTable Component
e960. Using a List JSpinner as a Cell Editor in a JTable Component

See also: Cells    Column Heads    Columns    Events    Layout    Rows    Scrolling    Selection    Sorting    Table Model    Tool Tips   


© 2002 Addison-Wesley.