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

How to HighLight a word in TextArea in Circular manner [closed]
Java: Can I create Generic-typed static classes?
Java: Converting ints to Strings in 2d array
How to make use of external JavaScript source file in JSP through simple java class
Java byte[] to float value conversion [closed]
Spring-Boot Resource Not Found when using executeable Jar
What is the purpose of calling defaultWriteObject() and defaultReadObject() in java serialization/deserialization? [duplicate]
Spring 4.0 Oauth 2 not working
(First time programming) How do you check an array of a class for a specific value?
Running Multiple Java Versions
how to use EmailAddressLocalService in liferay
How java interpreter picks up main function even when it is placed in inner class?
Spinner String item value get (not string name) android
ScrollPane content becomes blurry after dragging
Android Running SQL statement in background
How does ensureCapacity work in Java?

Categories

HOME
bluetooth
asp.net-core
netsuite
urbancode
json.net
react-virtualized
dot
vmware
alfresco
kalman-filter
yahoo-oauth
spring-cloud-stream
rubygems
ezpublish
nano-server
spring-kafka
midi
spring-xd
wheelnav.js
postgres-xl
collectd
timeout
clojurescript
django-admin
saxon
shared-hosting
lldb
swiftlint
riot.js
mps
autosys
shopware
phpfox
vision
subdomains
newline
skia
bluestacks
tinymce-4
stormpath
junit5
data-manipulation
typed.js
grails-3.1
catch-all
perlin-noise
windows-dev-center
vapor
uft-api
android-fingerprint-api
ansible-playbook
broadcastreceiver
botbuilder
nomethoderror
heightmap
reactive-cocoa-5
qwt
long-polling
hls.js
colorama
magma
angular-cache
ubuntu-10.04
make-install
bgp
uid
atk4
cakephp-3.1
ibaction
microbenchmark
inmobi
e10s
c++03
dia
website-monitoring
offloading
jscript.net
codeigniter-routing
gulp-less
neolane
fluentautomation
wp-query
dataservice
file-locking
cos
e4x
trusted
windows-phone-7.1.1
punbb
eclipse-templates
zpt
django-tagging
propagation
floating
dmx512
user-friendly
backcolor
virtual-functions
grid-system

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