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.