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(ta ble.getSel ectedRow() ,table.get SelectedCo lumn())){
//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.
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
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(ta
//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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, you have to tell your table cell editor that it has to become active at one click (which is default 2, I believe)
ASKER
Your solution, with a minor alteration, solved one of my problems:
((DefaultCellEditor)yourTa ble.getDef aultEditor (Float.cla ss)).setCl ickCountTo Start(1);
If I used getCellEditor() it would return null
Now I only need to selectAll() when the field is clicked
((DefaultCellEditor)yourTa
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.
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.
Wish I could have helped better for the 2nd part.