Re: JTextPane woes...



Frances <fdr58@xxxxxxxxx> wrote:

> I need to switch from JTextArea to JTextPane b/c need to change font
> color according to user input, but am running into all sorts of
> problems.. you can't specify a size in rows and columns like you can in
> JTextArea, setSize() is being ignored.. also why no append() method in
> JTextPane.. how do I achieve what append() method does... such
> complication simply b/c I need to change font color (JUST font color)
> according to user input... :(
>
> (this is for an IM chat window... so on top window need to display
> users' ID with their message.. ID needs to be a diff. font color..
> sounds simple.. but well, JTextPane making this very complicated..)
>
> would very much appreciate some help.. thank you..

Please calm down.

JTextArea.append() is just a shorthand for getDocument().insertString(getDocument.getLength(), %, null);

size in rows and columns does not make sense for JTextPane in the generic
case (because there is not one fixed font), but they can be done similar to
as JTextArea if desired (override getPreferredScrollableViewportSize and
maybe getPreferredSize, see JTextArea source; it is really not difficult).


Christian
.



Relevant Pages

  • Re: How to display text messages in a scrolling text area?
    ... high-level and thus often more simple to use than JTextArea. ... JEditorPane or JTextPane. ...
    (comp.lang.java.gui)
  • Re: Copy/Paste in an applet under MacOS
    ... > I wrote a text editing applet .. ... >..using a JTextArea or a JTextPane ... > (depending on what the user wants to write) and until now, ...
    (comp.lang.java.gui)
  • JTextPane newb
    ... formatting with the preferred style) ... JTextArea to the JTextPane? ... HTMLDocument.insertBeforeEnd .insertAfterEnd .insertBeforeStart and ...
    (comp.lang.java.gui)
  • Re: Text Area Colours
    ... I usually go for the JTextPane when I need formatted text. ... replaced your JTextArea with a JTextPane you need to update the way ... SimpleAttributeSet attr = new SimpleAttributeSet; ... is there a simple way to give a single String to the append method ...
    (comp.lang.java.gui)