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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:25:35+00:00 2026-05-31T12:25:35+00:00

From the Swing tutorial on text components : You may want to change the

  • 0

From the Swing tutorial on text components:

You may want to change the document’s text within a document listener. However, you should never modify the contents of a text component from within a document listener. If you do, the program will likely deadlock. Instead, you can use a formatted text field or provide a document filter.

I am confused. So what is the correct way to change the text eg. as a result of a KeyEvent ?

  • 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-31T12:25:36+00:00Added an answer on May 31, 2026 at 12:25 pm

    1) using DocumentListener for

    • output from JTextComponent to the GUI

    • HightLighter or Styled text

    2) DocumentFilter for filtering of

    • unwanted chars,

    • chars sequence(s),

    these filtered chars could be

    • replaced with another char (or with defined chars sequence)

    • removed (never will be displayed in the JTextComponent)

    3) similair funcionality to provide JFormattedTextFieldis possible to input to the JTextComponent only chars 0 - 9, decimal separator, negative sing,

    4)
    So what is the correct way to change the text eg. as a result of a KeyEvent ?

    use DocumentFilter

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

Sidebar

Related Questions

I've been using the following approach to create components and return values from Swing
I'm developing a utility class to handle Actions from Java Swing components; I would
I simply want to call a swing action from my own popup menu. But
I want to realize a simple JComponent-Drag-and-Drop with a preview from O.Reilly-Swing.Hacks Hack 69.
I have recently came upon odd situation; HTML formatted text in my Swing components
I am from Java Swing background. May I know why using XML to create
We want to migrate a project from Swing to JavaFX as the new UI
I have to open a page from class extended from javax.swing.AbstractAction class... Is that
This is pretty simple, I come from a swing/awt background. I'm just wondering what
I don't understand the rationale of this code, taken from javax.swing.event.EventListenerList docs: protected void

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.