Link to home
Start Free TrialLog in
Avatar of b_loco
b_loco

asked on

selectAll() in JTable field

Hi !

Just wanted to know how to select the entire field of a JTable when the user single clicks the field.

I've started to write a mouse listener but got stuck :

table.addMouseListener(new MouseListener() {
      public void mouseClicked(MouseEvent e){
       
      }
      public void mouseEntered(MouseEvent e){

      }
      public void mouseExited(MouseEvent e){

      }
      public void mousePressed(MouseEvent e){

      }
      public void mouseReleased(MouseEvent e){
        if(table.isCellEditable(table.getSelectedRow(),table.getSelectedColumn())){
           //What now?
        }
      }

    }
    );

Can I do it like this? If not, how can I do it then?

I don't know if it is important but the field holds a float value and I need to keep the validation.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So, you have to tell your table cell editor that it has to become active at one click (which is default 2, I believe)
Avatar of b_loco
b_loco

ASKER

Your solution, with a minor alteration, solved one of my problems:
((DefaultCellEditor)yourTable.getDefaultEditor(Float.class)).setClickCountToStart(1);
If I used getCellEditor() it would return null

Now I only need to selectAll() when the field is clicked
>> Your solution, with a minor alteration, solved one of my problems
Good.

>>Now I only need to selectAll() when the field is clicked
Mmmm.
Thanks for accepting.
Wish I could have helped better for the 2nd part.