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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:29:02+00:00 2026-05-30T03:29:02+00:00

I want to have a method like this on my DocumentFilter public void replaceUpdate(int

  • 0

I want to have a method like this on my DocumentFilter

public void replaceUpdate(int offset, int length, String text) {
        try {
            super.replace(byPass, offset, length, text, null);
        } catch (BadLocationException ex) {
            //error
        }
}

Currently in order to get an instance of FilterBypass (byPass on method above) , I need to get from the overridden method insertString :

private FilterBypass byPass;

@Override
    public void insertString(DocumentFilter.FilterBypass fb,
            int offset, String string, AttributeSet att)
            throws BadLocationException {
        byPass = fb;
        //some stuff here
        super.insertString(fb, offset, string, att);
    }

But this is causing me some problems. Can anyone suggest some different way of getting a FilterBypass? I can’t find a way to get a reference to the FilterBypass differently.

If I was to override its methods how should it be?

  • 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-30T03:29:03+00:00Added an answer on May 30, 2026 at 3:29 am

    For instance, here’s an SSCCE with a DocumentFilter which prevents the user from typing numbers into the document but allows the Swing Timer to do so.

    import java.awt.event.*;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import javax.swing.text.*;
    
    public class DocFilterPanel extends JPanel {
       private JTextArea textArea = new JTextArea(12, 50);
       private MyDocFilter myDocFilter = new MyDocFilter();
    
       public DocFilterPanel() {
          ((PlainDocument) textArea.getDocument()).setDocumentFilter(myDocFilter);
          int vsbPolicy = JScrollPane.VERTICAL_SCROLLBAR_ALWAYS;
          int hsbPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
          add(new JScrollPane(textArea, vsbPolicy , hsbPolicy));
    
          int timerDelay = 1000;
          new Timer(timerDelay , new ActionListener() {
    
             @Override
             public void actionPerformed(ActionEvent e) {
                myDocFilter.setFilter(false);
                textArea.append("12345\n");
                myDocFilter.setFilter(true);
             }
          }).start();
       }
    
       private static void createAndShowGui() {
          DocFilterPanel docFilterPanel = new DocFilterPanel();
    
          JFrame frame = new JFrame("DocFilterTest");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(docFilterPanel);
          frame.pack();
          frame.setLocationByPlatform(true);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                createAndShowGui();
             }
          });
       }
    }
    
    class MyDocFilter extends DocumentFilter {
       private static final String REMOVE_REGEX = "\\d";
       private boolean filter = true;
    
       public boolean isFilter() {
          return filter;
       }
    
       public void setFilter(boolean filter) {
          this.filter = filter;
       }
    
       @Override
       public void insertString(FilterBypass fb, int offset, String text,
             AttributeSet attr) throws BadLocationException {
          if (filter) {
             text = text.replaceAll(REMOVE_REGEX, "");
          }
          super.insertString(fb, offset, text, attr);
    
       }
    
       @Override
       public void replace(FilterBypass fb, int offset, int length, String text,
             AttributeSet attrs) throws BadLocationException {
          if (filter) {
             text = text.replaceAll(REMOVE_REGEX, "");
          }
          super.replace(fb, offset, length, text, attrs);
    
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method like this: public void foo(String str){ do.something(); do.anotherthing(); do.somethingelse(); if(str.compareTo(choiceA)==0){
I have a method like this: -(void)A:(int)a B:(int)b{ } and want to put the
I want to implement a method like this: public Iterator<File> getFiles(String root) { //
If I have a method like this private void setStringList(List<String> aList) { ... }
I have a method on an interface that looks like this and I want
I have a method public void MyMethod(decimal val) { } I want to call
I have a method that looks like this: try { doStuff(); } catch (Exception
Let's assume I have a method like this: public static List<T> Get<T>(this SomeObject<T>, Expressions<Func<T,bool>>
I have a method like this: private static double ComputePercentage(ushort level, ushort capacity) {
I have method for converting array of Booleans to integer. It looks like this

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.