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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:53:40+00:00 2026-05-29T04:53:40+00:00

I’ve a text field which extends javax.swing.JTextField and also have document listener like this

  • 0

I’ve a text field which extends javax.swing.JTextField and also have document listener like this

public class MyTetField extends javax.swing.JTextFiled{
     public MyTextField(){
          super();
          // Document listener to check mandatory functionality
          getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
            /**
             * If the text is changed then this event will be fired.
             */
            public void changedUpdate(javax.swing.event.DocumentEvent e) {
            }
            /**
             * If some value is removed then this event is fired.
             */
            public void removeUpdate(javax.swing.event.DocumentEvent e) {
            }
            /**
             * If some value is auto set, this event will be called
             * @param e The value change event
             */
            public void insertUpdate(javax.swing.event.DocumentEvent e) {
                if (getText().trim().equals("")){
                    setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.RED));
                }else{
                    setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.GRAY));
                }
            }
        });
     }
}

Now I want another text field say MyTextField1extending MyTextField which should have this mandatory check and also to get some information from DB after checking mandatory field and if some value is given. I do not want to write the same document listener code in that. Is it possible to extend document listener which we added in MyTextField OR should I go for focus listener?

  • 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-29T04:53:40+00:00Added an answer on May 29, 2026 at 4:53 am
    1. There is no need to extend JTextField for what you are doing. Most of the times, there is no need to extend the Swing components.
    2. What your listener does in your MyTextField class looks remarkably similar to what a JFormattedTextField does. You might want to consider using that class instead
    3. To actually answer your question, you can extend your MyTextField class and just add another DocumentListener which does some extra checks. You will keep your original functionality since the super class will add its own DocumentListener
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a reasonable size flat file database of text documents mostly saved 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.