Update height problem with JTextPane after SetText()

Joined
Mar 2, 2009
Messages
1
Reaction score
0
I am using a JTextPane for a log, and each time I set text which makes the height of the JTextPane higher than the height of the JScrollPane, it is not neccessarily updated.
To make an example, I have used some System.out.println to illustrate:

Code:
System.out.println("Before Add text "+textLogArea.getHeight() + " - ScrollPaneheight: " + textScrollPane.getViewport().getHeight());

textLogArea.setText(textLogArea.getText()+newText);
			
System.out.println("After Add text. "+textPane.getHeight() + " - ScrollPaneheight: " + textScrollPane.getViewport().getHeight());
System.out.println("After Add text. "+textPane.getHeight() + " - ScrollPaneheight: " + textScrollPane.getViewport().getHeight());
System.out.println("After Add text. "+textPane.getHeight() + " - ScrollPaneheight: " + textScrollPane.getViewport().getHeight());
System.out.println("After Add text. "+textPane.getHeight() + " - ScrollPaneheight: " + textScrollPane.getViewport().getHeight());

Sometimes I get a difference between the Before and After sysouts, but sometimes I get a differences between the After sysouts.
Why does the difference occur, and is there something I can do about it ? It is as the JTextPane rests its height to its original height for a short while, and then suddenly expands back to its proper height.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top