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 8557301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:32:39+00:00 2026-06-11T15:32:39+00:00

Can textField in JTable add some text automatically ? (without javaScript) Just like auto

  • 0

Can textField in JTable add some text automatically ? (without javaScript)

Just like auto add colon(:) for “Time” when user type number 2 digits or lost focus from that field.

I try using some invokeLater(), KeyListener() and editCellAt(), it work only when I get into the field (double click and F2), but doesn’t work if I only click and type.

private JTable getTblMaster() {
if (tblMasterData == null) {
    tblMasterData = new JTable() {

           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(column == 2){
                     EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {

                            if(((JTextComponent) editor).getText().length() == 2){
                                ((JTextComponent) editor).setText(((JTextComponent) editor).getText() + ":");
                            }                               
                        }   
                     });                     
                }
           */
                return result;
            }
            public TableCellEditor getCellEditor(int row, int column) {

                TableColumn tableColumn = getColumnModel()
                        .getColumn(column);

                TableCellEditor editor = tableColumn.getCellEditor();
                try {
                    if (editor == null) {
                            final JTextField text = new JTextField();
                       /* 
                           SwingUtilities.invokeLater(new Runnable() {

                                    @Override
                                    public void run() {
                                        if(text.getText().length() == 2){
                                            text.setText(text.getText() + ":");
                                        }                                       
                                    }                               
                                });


                            text.addKeyListener(new java.awt.event.KeyAdapter() {
                                public void keyPressed(KeyEvent e){
                                    if(text.getText().length() == 2){
                                        text.setText(text.getText() + ":");
                                    }
                                }
                                public void keyReleased(KeyEvent e){
                                    if(text.getText().length() == 2){
                                        text.setText(text.getText() + ":");
                                    }
                                }
                            });
                        */
                            editor = new DefaultCellEditor(text);
                        ;
                        return editor;
                    }
                } catch (Exception e) {
                    LogWriter.error(e);
                }
                return editor;
            }
        };
    }
    return tblMasterData;
}
  • 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-06-11T15:32:40+00:00Added an answer on June 11, 2026 at 3:32 pm

    On the textfield of your TableCellEditor, add a DocumentListener to the Document of the JTextField. Within the DocumentListener, add your method that should append/modify the text of the textfield.

    If I remember correctly, you will need to perform the modification within a SwingUtilities.invokeLater because I think that JTextField prevents text-modification during the firing of events (well actually, it is the Document which will prevent that).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<form name=myForm> <input type=text name=f['cart']]['product_name']/> </form> How can I access textfield's value using javascript?
How can I create the textfield that can accept image and text like the
I have a textfield where the user can type what ever he want into
I've got a short question. How can I update a TextField without using an
I am trying to build a form where users can add a text field
How can I implement a multiple line textfield like what I see in the
In wicket textfield how can I align text and cursor to right of the
How can I copy the text from a textfield?
Can somebody tell me how to focus the html textfield using JavaScript? I am
does anyone know, how I can create a Textfield, like the To Field in

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.