Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

[swing] JTextPane - Performance and many characters

Thread view: 
Thomas Barth - 16 Apr 2004 20:28 GMT
Hi,
when adding thousends of characters to a JTextPane (Chatlog), resizing
becomes very slowly. 100% of the CPU power is used for one or two
seconds also blocking my application (WinXP, Pentium M 1,3GHz) .
It seems as if the whole text of its document is recalculates for word
and line wrapping. I hoped that only the text represented by the viewport
of a JScrollPane would be recalculated.

Placing JTextPanes
--------------------------------------

   txtDialog = new MyTextPane(sChan);

   scrollDialog = new JScrollPane();
   scrollDialog.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
   scrollDialog.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

   splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollDialog, scrollUser);
   splitPane.setOneTouchExpandable(true);
   scrollDialog.getViewport().setView(txtDialog);

   this.add(splitPane, BorderLayout.CENTER);

MyTextPane itself
--------------------------
...
private StyledDocument document = (StyledDocument)MyTextPane.this.getStyledDocument();
private SimpleAttributeSet attributes = new SimpleAttributeSet();
...
private void insertStr(char ch, String sNewLine) {
   try {
     document.insertString(document.getLength(), "" + ch, attributes);
   } catch (Exception e) {
     System.out.println("Fehler document.insertString: " + e.getMessage());
   }
 }

Before adding the characters to the document, the string is analysed for its attributes
like bold, underline, color, size, font etc.

private void setAttributes() {
   StyleConstants.setFontSize(attributes, iFontSize);
   StyleConstants.setFontFamily(attributes, sFont);
   StyleConstants.setBold(attributes, bBold);
   StyleConstants.setUnderline(attributes, bUnderline);
...

Is there possibility keeping the load low other than limitting the amount of characters?

I appriciate any help you can give me,

Thomas
Roedy Green - 17 Apr 2004 06:07 GMT
>Is there possibility keeping the load low other than limitting the amount of characters?

Display with a JTable instead.  It requires blocking out in a grid or
lines.

Then it can find the proper lines to display instantly.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.