classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: patch for BasicTextAreaUI makes line-wrapping work wit


From: Anthony Balkissoon
Subject: [cp-patches] FYI: patch for BasicTextAreaUI makes line-wrapping work with no hacks
Date: Mon, 31 Oct 2005 16:35:12 -0500

This is the patch that I mentioned earlier would be required for
line-wrapping to work.  The propertyChange method in BasicTextAreaUI
checks to see if line wrapping was turned on or off, or if the style of
wrapping was changed, and if so calls modelChanged.  Model changed calls
BasicTextAreaUI.create, and this method is now fixed to not just return
a PlainView, but to return a WrappedPlainView if needed (line wrapping
on) and a PlainView if not.

I also added some necessary repaints in WrappedPlainView and a
revalidate in BasicTextUI.

At the bottom of this message I've pasted a little program that displays
some text in a regular JTextArea (no line wrapping), waits 2 seconds and
turns on line wrapping, then waits another 2 seconds and changes the
style of the wrapping from character-boundary to word-boundary.  You can
also resize the window and watch the wrapping adjust itself.

2005-10-31  Anthony Balkissoon  <address@hidden>

        * javax/swing/plaf/basic/BasicTextAreaUI.java:
        (create): Added docs.  Create WrappedPlainView instead of PlainView if
        the text area has line wrapping turned on.
        (propertyChange): New API method.  If line wrapping is turned on or off
        or if the style of wrapping (character or word) is changed, call 
        modelChanged().
        * javax/swing/plaf/basic/BasicTextUI.java:
        (setView): Call revalidate and repaint after setting the View.
        * javax/swing/text/WrappedPlainView.java:
        (insertUpdate): Repaint the container.
        (removeUpdate): Likewise.
        (changedUpdate): Likewise.


*** PROGRAM TO DEMONSTRATE LINE-WRAPPING IN JTEXTAREAS ***
import javax.swing.*;

public class Editor
{
  public static void main (String[] args) 
  {
    JTextArea ta = new JTextArea();
    ta.setText("this is some really extrasuperduperlong text that will
wraparoundateither character or word boundaries");
    JFrame jf = new JFrame();
    jf.add(ta);
    jf.setSize(150,200);
    jf.show();
    try
      {
        Thread.sleep(2000);
        ta.setLineWrap(true);
        Thread.sleep(2000);
        ta.setWrapStyleWord(true);
      }
    catch (Exception e)
      {
      }
  }
}


--Tony

Attachment: BasicTextAreaUIDetectLineWrap.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]