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

  • Home
  • SEARCH
  • 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 6631247
In Process

The Archive Base Latest Questions

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

I am a having problem with appending a text to a JTextArea after Using

  • 0

I am a having problem with appending a text to a JTextArea after Using a DocumentFilter,
I need to append a string on the JTextArea after the text has been uploaded from a file and also return a string from a JTextArea of another JFrame to the specified JTextArea

Everything worked perfectly when I didn’t use the DocumentFilter.FilterBypass until when I added it. It still works a little but only when comma(,) or space(” “) isn’t added. Which is not to the specification I was given.

How can I solve this? Or is there any algorithm or implementation that doesn’t give this problem?

This is the insertString code to filter the length, and only allow space and comma

public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
    // if (string == null || string.trim().equals("") || string.equals(","))
    // {
    // return;
    // }

    if (isNumeric(string)) {
        // if (this.length > 0 && fb.getDocument().getLength() +
        // string.length()
        // > this.length) {
        // return;
        // }
        if (fb.getDocument().getLength() + string.length() > this.length || string.trim().equals("") || string.equals(",")) {
            this.insertString(fb, offset, string, attr);
        }
        // if (string == null || string.trim().equals("") ||
        // string.equals(",")) {
        // return;
        // }
        super.insertString(fb, offset, string, attr);
    }
    else if (string == null || string.trim().equals("") || string.equals(",")) {
        super.insertString(fb, offset, string, attr);
    }

}

@Override
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
    if (isNumeric(text)) {
        if (this.length > 0 && fb.getDocument().getLength() + text.length() > this.length) {
            return;
        }
        super.insertString(fb, offset, text, attrs);
    }
}

/**
 * This method tests whether given text can be represented as number. This
 * method can be enhanced further for specific needs.
 * 
 * @param text
 *            Input text.
 * @return {@code true} if given string can be converted to number;
 *         otherwise returns {@code false}.
 */
private boolean isNumeric(String text) {
    if (text == null || text.trim().equals("") || text.equals(",")) {
        return true;
    }
    for (int iCount = 0; iCount < text.length(); iCount++) {
        if (!Character.isDigit(text.charAt(iCount))) {
            return false;
        }
    }
    return true;
}

The other two functions (append from file & append from a different frame) I want to implement innocently by just appending their string values to the JTextArea that is filtered using this. But is being refused by super.insertString(…..)

  • 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-25T22:31:08+00:00Added an answer on May 25, 2026 at 10:31 pm

    I’m not sure I really got your question. If you want to have a filter where you can paste complete numbers or “,” and whitespace (end or beginning or entered) but cannot paste any other text you can just change your isNumeric function:

    private boolean isNumeric(String text) {
       text = text.trim();
       if(",".equals(text)) return true;
       ParsePosition position = new ParsePosition(0);
       java.text.NumberFormat.getNumberInstance().parse(text, position);
       return position.getIndex() == text.length();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem playing back audio data after appending extra recording to it.
I am having problem in getting reference of Ajax control extender using $find() or
I'm having problem restricting a query in mdx, using except function at where clause.
Hi I am having no problem writing to or appending to a file, the
I'm trying to read from a text file using the read function and store
I am having a problem appending a few options to an array of modules.
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
We're having problem with a huge number of legacy stored procedures at work. Do
I'm having problem in the following line: rd.PrintOptions.PaperSize = PaperSize.PaperFanfoldStdGerman; it throws an exception
We are having problem with the server migration. We have one application that are

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.