java


Wrap text in a JTextPane when pane width exceeds a specified value


My GUI displays a log in a JTextPane, which is inside a JScrollPane, which occupies the left side of a JSplitPane. The right side of the JSplitPane holds the interesting part of the GUI. The width of the log pane is typically narrow (20), but is increased when the user wants to view the activity. If the log text is wrapped the displayed text is pretty useless when the log pane is narrow, but if some log entries are long, the size of the log pane needs to be increased to occupy most of the GUI to view the entries.
I understand that JTextPane does not naturally wrap text, and that other postings on Stack Overflow describe how text can be wrapped. However, I would like the text to be wrapped only when the pane is wider that some supplied limit, say 100. So, when the pane is narrow, just the beginning of each message is shown, and if the user wants to see the full text, the pane width is increased and the text is wrapped to the window width.
If there's no way to do this, I will turn off wrapping and format the text to some fixed width before writing it to the pane.
Thanks in advance!
I understand that JTextPane does not naturally wrap text
That is wrong. By default a JTextPane does wrap text.
Check out Text Pane No Wrap for more information on this topic which forms the basis for the solution below.
You need to override the getScrollableTrackViewportWidth() method. I think it should be:
JTextPane textPane = new JTextPane()
{
public boolean getScrollableTracksViewportWidth()
{
return getParent().getSize().width > 100;
}
};

Related Links

Spring and Hibernate: use same entity class and repository from multiple databases (data sources)
Can't see source java class in eclipse
I am getting this error while running Javafx Gluon
How do I add buttons with specific id and invoke javabean method with that id as argument for every row in a dataTable?
ContainerRequestFilter is not executed in JAX-RS / RESTEasy application
IndexOutOfBoundsException error in gridview filter
AquireToken Callback Not Working
Java-8 lambda expression equivalent for traditional for
Cannot pick a random search result using Selenium with java
recording audio on android 6.0+ while whatapp is active
Spring-MVC : Rate Limit per logged in user
What is the codenameone calendar component lifecycle?
how to add scrollview dynamically to dynamic table rows
Android: transferring Context and activity from a fragment to a class
MyBatis with Guava multimap
Making Java GUI changes appear during Eclipse debug session

Categories

HOME
arduino-uno
kde
onedrive
fft
syntax
dot
malloc
twitter-bootstrap-4
jgroups
jpeg
survey
ebean
cross-validation
esper
wheelnav.js
carthage
dynamics-crm-online
quartz-scheduler
clojurescript
libtiff
django-admin
windows-7-x64
reverse-proxy
arabic
web-sql
tapestry
extjs5
captiveportal
centos6.5
facebook-access-token
bootstrap-duallistbox
fifo
buck
bluestacks
ioio
pdb
siesta-swift
subset-sum
geopositioning
mmenu
x11-forwarding
unoconv
optix
ibpy
nand2tetris
convertapi
angular2-meteor
jsch
rainbowtable
youcompleteme
network-flow
filepicker
zip4j
theming
sage-one
domain-model
np-complete
sqlbulkcopy
spring-mongodb
mediaelement
quartz-composer
background-service
pintos
google-feed-api
azure-sdk
home-directory
dstu2-fhir
packagist
rvest
bluegiga
associative-array
jfugue
simple-framework
pundit
tarjans-algorithm
varargs
android-listview
twirl
remobjects
dereference
xc16
phpthumb
hippomocks
poller
kgdb
mechanize-ruby
hyprlinkr
meteor-velocity
centos5
mcts
floating-point-precision
bulkloader
gridcontrol
dataadapter
eventual-consistency
django-nonrel
hungarian-algorithm
seed
android-hardware
google-email-migration
automount
fireworks
pydot
sql-server-profiler
html-input
perfect-hash
compiler-specific
mtj
project-hosting
paul-graham

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App