?
Solved

selectAll() in JTable field

Posted on 2004-11-03
5
Medium Priority
?
178 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:b_loco
  • 4
5 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 150 total points
ID: 12483679
Use

   ((DefaultCellEditor)yourTable.getCellEditor()).setClickCountToStart(1);
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12483694
So, you have to tell your table cell editor that it has to become active at one click (which is default 2, I believe)
0
 
LVL 2

Author Comment

by:b_loco
ID: 12483913
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
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12483986
>> Your solution, with a minor alteration, solved one of my problems
Good.

>>Now I only need to selectAll() when the field is clicked
Mmmm.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12542483
Thanks for accepting.
Wish I could have helped better for the 2nd part.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question