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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:43:21+00:00 2026-05-15T10:43:21+00:00

I currently have a JTextPane that will be displaying text coming in from different

  • 0

I currently have a JTextPane that will be displaying text coming in from different streams. The way that the user can tell which stream the text came from is that the text from each stream has a different Style to it. Is there a way to make a Style that will hide the text so that I can filter out different pieces of text?

Thank you.

  • 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-15T10:43:21+00:00Added an answer on May 15, 2026 at 10:43 am

    You can (kind of) fake it by using a 0 font size and matching the background of the component:

    public static void main(String[] args) throws Exception {
        JTextPane pane = new JTextPane();
    
        Style regular = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
        Style invisible = pane.getStyledDocument().addStyle("invisible", regular);
        StyleConstants.setFontSize(invisible, 0);
        StyleConstants.setForeground(invisible, pane.getBackground());
        pane.getStyledDocument().insertString(pane.getStyledDocument().getLength(), 
                "Hello, ", null);
        pane.getStyledDocument().insertString(pane.getStyledDocument().getLength(), 
                "cruel ", pane.getStyledDocument().getStyle("invisible"));
        pane.getStyledDocument().insertString(pane.getStyledDocument().getLength(), 
                "world!", null);
        pane.setPreferredSize(new Dimension(500, 500));
    
        JFrame frame = new JFrame();
        frame.setLayout(new BorderLayout());
        frame.add(pane, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack(); frame.setVisible(true);
    }
    

    The length of the invisible string above doesn’t even seem to have an affect on the space between the visible components. But rest assured it’s still there, as copying from the pane will prove.

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

Sidebar

Related Questions

Currently have a drop down menu that is activated on a hover (from display:none
I currently have the following code that retrieves data from the database and then
I am implementing a JTextPane-based text editor. Currently, when I have a piece of
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
Problem: I have a method that creates a list from the parsed ArrayList. I
Currently have this to get a value from the registry in TSQL. However, I
Currently I have the following code for a project that represents some probability trees
I currently have: $('.tweet').text(function (_, text) { var exp = /(#(\S+))/g; return text.replace(exp, '<a

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.