Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6966947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:15:29+00:00 2026-05-27T16:15:29+00:00

i have seen some example of doing it but i still can’t understand and

  • 0

i have seen some example of doing it but i still can’t understand and not able to implement it.

What i want to do is on cell change (focus), the next selected cell will have all the text selected, ready for user to totally change it..

Any ideas on how to do it ?

//update//
somehow i managed to come out with the following class but

implement this
tblLayers.setDefaultEditor(String.class, new Classes.CellEditor());

yields nothing, the “Not supported yet.” is NOT thrown ..

how should I solve this problem ?

import java.awt.Component;
import java.util.EventObject;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;


public class CellEditor extends JTextField implements TableCellEditor {


public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    //        final JTextField ec = (JTextField) editorComponent;
    //
    //        ec.setText((String) value);
    //
    //        // selectAll, so that whatever the user types replaces what we just put there
    //        ec.selectAll();
    //
    //        SwingUtilities.invokeLater(new Runnable() {
    //
    //            public void run() {
    //                // make the component take the keyboard focus, so the backspace key works
    //                ec.requestFocus();
    //
    //                SwingUtilities.invokeLater(new Runnable() {
    //
    //                    public void run() {
    //                        // at this point the user has typed something into the cell and we
    //                        // want the caret to be AFTER that character, so that the next one
    //                        // comes in on the RHS
    //                        ec.setCaretPosition(ec.getText().length());
    //                    }
    //                });
    //            }
    //        });
    //        return editorComponent;


    throw new UnsupportedOperationException("Not supported yet.");
}

public Object getCellEditorValue() {
    throw new UnsupportedOperationException("Not supported yet.");
}

public boolean isCellEditable(EventObject anEvent) {
    throw new UnsupportedOperationException("Not supported yet.");
}

public boolean shouldSelectCell(EventObject anEvent) {
    throw new UnsupportedOperationException("Not supported yet.");
}

public boolean stopCellEditing() {
    throw new UnsupportedOperationException("Not supported yet.");
}

public void cancelCellEditing() {
    throw new UnsupportedOperationException("Not supported yet.");
}

public void addCellEditorListener(CellEditorListener l) {
    throw new UnsupportedOperationException("Not supported yet.");
}

public void removeCellEditorListener(CellEditorListener l) {
    throw new UnsupportedOperationException("Not supported yet.");
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:15:30+00:00Added an answer on May 27, 2026 at 4:15 pm

    regarding editorComponent, where do I initialize this variable?

    The variable editorComponent is a field of DefaultCellEditor.

    Instead of

    class CellEditor extends JTextField implements TableCellEditor
    

    consider

    class CellEditor extends DefaultCellEditor
    

    Then you can do something like this:

    @Override
    public Component getTableCellEditorComponent(JTable table,
            Object value, boolean isSelected, int row, int column) {
        JTextField ec = (JTextField) editorComponent;
        if (isSelected) {
            ec.selectAll();
        }
        return editorComponent;
    }
    

    Addendum: As suggested by @Edoz and illustrated in this complete example, you can selectively re-queue the selectAll() when a mouse-click initiates editing.

    JTable table = new JTable(model) {
    
        @Override // Always selectAll()
        public boolean editCellAt(int row, int column, EventObject e) {
            boolean result = super.editCellAt(row, column, e);
            final Component editor = getEditorComponent();
            if (editor == null || !(editor instanceof JTextComponent)) {
                return result;
            }
            if (e instanceof MouseEvent) {
                EventQueue.invokeLater(() -> {
                    ((JTextComponent) editor).selectAll();
                });
            } else {
                ((JTextComponent) editor).selectAll();
            }
            return result;
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please give me some examples of jump table usage. I have seen this example
I have seen some related questions but none focusing on the specific problem I
i have seen some hand rolled solutions but does jquery out of the box
I have seen some of the other answers on this topic but dont really
I have always seen Throwable/Exception in the context of errors. But I can think
Have seen some similar questions: What is the difference between a JavaBean and a
I have seen some people in SO commenting that Singleton Pattern is an anti-pattern.
I have seen some mails which has HTML content embedded in them. The content
I have seen some instances where people will say you have to use JS
I have seen some developers use the return statement in a catch block. Why/when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.