Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #289

Re: Problem with JTextPan

From "Bart Cremers" <bart.cremers@THRWHITE.remove-dii-this>
Subject Re: Problem with JTextPan
Message-ID <1164975773.608818.91360@73g2000cwn.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
References <1164844196.063735.74270@l12g2000cwl.googlegroups.com>
Date 2011-04-27 15:26 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui

Bartek wrote:
> Hello
>
> I try to use JTextPane with HTML content, but I've got a problem with
> word wrapping. When I use ordinary plain text, everything is fine, but
> if I change content type to "text/html" word wrapping is "switching
> off". Longer texts are getting out of the visible JTextPane content. Is
> there any possibilities to use both HTML and word wrapping in JTextPane
> ?
>
> My second problem is connected with scrolling JTextPane. I try to
> create simple chat applicaton, and I need to present incoming messages
> in JTextPane. Unfortunately when I'm adding new content to the end of
> the JTextPane, the vertical scroll bar is going up (new content is
> getting invisible). Of course I can scroll down the vertical scroll bar
> programmatically, but when I'm doing this, my JTextPane is blinking :(
> (because first it is going up, then return to the bottom). So is there
> any possibility to avoid this ? I would like to change the vertical
> scroll bar behaviour to prevent going up when adding new content. I
> tried to extend JTextPane and change some of it's method e.g. those
> connected with Scrollable interface, but with no effect :(. Maybe you
> can help me with this ?
>
> Best regards
>
> BartekS

I don't know about your first problem. I've never noticed word wrapping
not working in a JTextPane.

For the second problem the solution is quite simple. Whenever you
append text to the textpane simply move the cursor to the final
position in the pane:

        Document document = textPane.getDocument();
        document.insertString(document.getLength(), text, null);
        textPane.setCaretPosition(document.getLength());

Moving the cursor takes care of the scrolling as well. And because of
the way swing works, the repaints needed for this are combined, so the
flicker will be reduced.

Regards,

Bart

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar


Thread

Problem with JTextPane wo "Bartek" <bartek@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: Problem with JTextPan "Bart Cremers" <bart.cremers@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000

csiph-web