Painting a region of DefaultStyledDocument content on to JTextPane

Posted on 2011-10-27
Medium Priority
Last Modified: 2012-05-12
I have huge amount of text added to defaultStyledDocument, if I paint whole style document content on to JTextPane, it takes high CPU for painting huge text.
I would like to paint portion of  defaultStyledDocument's content (may be based on offset) based on scroll pane linked to JTextPane.
Please let me know how do I achieve this.
Question by:harishalwala
  • 4
  • 2
LVL 86

Expert Comment

ID: 37038606
Why paint - why not copy the content?

Author Comment

ID: 37038633
I use styledDocument.insert() api to add the text content.
do you mean something else?
LVL 86

Expert Comment

ID: 37038712
I'm interested in why you use the term 'paint' and am wondering if you're using it for a specific reason
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 37043650
My intention is to say show part of the styleddocument content on to the TextPane.
Hope you are clear now.
LVL 86

Accepted Solution

CEHJ earned 1000 total points
ID: 37043799
Use http://download.oracle.com/javase/6/docs/api/javax/swing/text/AbstractDocument.html#getText(int, int)
ta.setText(doc.getText(0, 255));

Open in new window

LVL 86

Expert Comment

ID: 37049592

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question