selectAll() in JTable field

Posted on 2004-11-03
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){
           //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.
Question by:b_loco
    LVL 37

    Accepted Solution


    LVL 37

    Expert Comment

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

    Author Comment

    Your solution, with a minor alteration, solved one of my problems:
    If I used getCellEditor() it would return null

    Now I only need to selectAll() when the field is clicked
    LVL 37

    Expert Comment

    >> Your solution, with a minor alteration, solved one of my problems

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

    Expert Comment

    Thanks for accepting.
    Wish I could have helped better for the 2nd part.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now