Line wrapping in Java??

Hi,
Can anyone tell me if there is a class to handle line wrapping in Java?
I'm working on a Java Mail application that deals with fairly lengthy email message bodies. The problem is in the actual email, the message body appears in a lengthy horizontal single line which is rather inconvenient to read.
I'd like to break the message body into convenient 80 character lines that takes word boundries into account so that there are no broken words at the end of a line.
Thanks,
Veena

Well the easiest way would be to put line breaks when you want them.
"\n" is the line break character.
So String("aaaaa\naaaaa");
Should appear as
aaaaa
aaaaa

Similar Messages

  • How to use line wrapping and line spacing in java?how to use line wrapping

    how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?

    Hello,
    You should post your question at:
    http://java.forum.sun.com
    Thanks
    - Rose

  • How to use line wrapping and line spacing in java?

    how to use line wrapping and line spacing in java?

    Hi,
    This is explained in the java Tutorial. Please see the link:
    http://java.sun.com/docs/books/tutorial/i18n/text/line.html
    and find some sample examples.
    Hope this helps,
    --Sun/DTS                                                                                                                                                                                                                                                                                                                                                                                       

  • Problems with JTextPane line wrapping

    Hi to all.
    I'm using a code like this to make editable a figure that I paint with Java 2D. This JTextPane don't has a static size and for that, the text in it cannot be seen affected by the natural line wrap of the JTextPane component. The problem is that I have to set a maximun size for the JTextPane and I want to use the line wrap only when the width of the JTextPane be the maximun width. How can I do this?
    public class ExampleFrame extends JFrame {
        ExamplePane _panel;
        public ExampleFrame() {
            this.setSize(600, 600);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            _panel = new ExamplePane();
            getContentPane().add(_panel);
            this.setVisible(true);
        public static void main(String[] args) {
            ExampleFrame example = new ExampleFrame();
        public class ExamplePane extends JPanel {
            public ExamplePane() {
                this.setBackground(Color.RED);
                this.setLayout(null);
                this.add(new ExampleText());
        public class ExampleText extends JTextPane implements ComponentListener, DocumentListener,
                KeyListener {
            public ExampleText() {
                StyledDocument doc = this.getStyledDocument();
                MutableAttributeSet standard = new SimpleAttributeSet();
                StyleConstants.setAlignment(standard, StyleConstants.ALIGN_RIGHT);
                doc.setParagraphAttributes(0, 0, standard, true);
                this.setText("Example");
                this.setLocation(300, 300);
                this.setSize(getPreferredSize());
                this.addComponentListener(this);
                getDocument().addDocumentListener(this);
                this.addKeyListener(this);
            public void componentResized(ComponentEvent e) {
            public void componentMoved(ComponentEvent e) {
            public void componentShown(ComponentEvent e) {
            public void componentHidden(ComponentEvent e) {
            public void insertUpdate(DocumentEvent e) {
                Dimension d = getPreferredSize();
                d.width += 10;
                setSize(d);
            public void removeUpdate(DocumentEvent e) {
            public void changedUpdate(DocumentEvent e) {
            public void keyTyped(KeyEvent e) {
            public void keyPressed(KeyEvent e) {
            public void keyReleased(KeyEvent e) {
    }Thanks for read.

    I'm working hard about that and I can't find the perfect implementation of this. This is exactly what I want to do:
    1. I have a Ellipse2D element painted into a JPanel.
    2. This ellipse is painted like a circle.
    3. Into the circle there's a text area, that user use to name the cicle.
    4. The text area is a JTextPane.
    5. When the user insert a text area, it can increase it size, but it can't be bigger than the circle that it contains.
    6. There is a maximun and a minimun size for the circle.
    7. When the user write into de JTextPane, it grows until arriving at the limit.
    8. When the JTextPane has the width size limit, if the user writes more text into it, the JTextPane write it into another line.
    9. The size of the JTextPane has to be the optimun size, it cannot have empty rows or empty lines.
    This code does all this except 9, cause if the user remove some text of the text area, the form of the JTextPane changes to a incorrect size.
    public class ExampleFrame extends JFrame {
        ExamplePane _panel;
        public ExampleFrame() {
            this.setSize(600, 600);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            _panel = new ExamplePane();
            getContentPane().add(_panel);
            this.setVisible(true);
        public static void main(String[] args) {
            ExampleFrame example = new ExampleFrame();
        public class ExamplePane extends JPanel {
            public ExamplePane() {
                this.setBackground(Color.RED);
                this.setLayout(null);
                this.add(new ExampleText());
        public class ExampleText extends JTextPane implements ComponentListener, DocumentListener,
                KeyListener {
            public ExampleText() {
                StyledDocument doc = this.getStyledDocument();
                MutableAttributeSet standard = new SimpleAttributeSet();
                StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
                doc.setParagraphAttributes(0, 0, standard, true);
                this.setText("Example");
                this.setLocation(300, 300);
                this.setSize(getPreferredSize());
                //If it has the maximun width and the maximun height, the user cannot
                //write into the JTextPane
                /*AbstractDocument abstractDoc;
                if (doc instanceof AbstractDocument) {
                abstractDoc = (AbstractDocument) doc;
                abstractDoc.setDocumentFilter(new DocumentSizeFilter(this, 15));
                this.addComponentListener(this);
                getDocument().addDocumentListener(this);
                this.addKeyListener(this);
            public void componentResized(ComponentEvent e) {
            public void componentMoved(ComponentEvent e) {
            public void componentShown(ComponentEvent e) {
            public void componentHidden(ComponentEvent e) {
            public void insertUpdate(DocumentEvent e) {
                Runnable doRun = new Runnable() {
                    public void run() {
                        int MAX_WIDTH = 200;
                        Dimension size = getSize();
                        Dimension preferred = getPreferredSize();
                        if (size.width < MAX_WIDTH) {
                            size.width += 10;
                        } else {
                            size.height = preferred.height;
                        setSize(size);
                SwingUtilities.invokeLater(doRun);
            public void removeUpdate(DocumentEvent e) {
                this.setSize(this.getPreferredSize());
            public void changedUpdate(DocumentEvent e) {
            public void keyTyped(KeyEvent e) {
            public void keyPressed(KeyEvent e) {
            public void keyReleased(KeyEvent e) {
    }I know that the problem is into the removeUpdate method, but I have to set to the JTextPane, allways the optimun size, how can I do this?
    Thanks to all.
    Edited by: Daniel.GB on 06-jun-2008 18:32

  • Center text in a text component with line wrapping

    I need to display dynamic text in a text component. I need line wrapping (on work boundaries) and also need horizontal and vertical center alignment.
    How do I do this? I saw a previous post on aligning text in a JTextArea that said to use a JTextPane but I don't see in JTextPane how to do word wrapping.
    Thanks,
    John

    //  File:          SystemInfoWindow.java.java
    //  Classes:     SystemInfoWindow
    //  Package:     utilities.msglib
    //  Purpose:     Implement the SystemInfoWindow class.
    //     Author:          JJB 
    //     Revision History:
    //     Date            By   Rel#  Description of change
    //     =============  ===  ====  ===============================================
    //     Jul 3, 2006   JJB  1.00  Original version
    //  Public Types / Classes          Type Description
    //  ========================     =============================================
    //     SystemInfoWindow
    package utilities.msglib;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.JTextPane;
    import javax.swing.SwingUtilities;
    * TODO Enter description
    class SystemInfoWindow extends JDialog {
          * @param args
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        Test thisClass = new Test();
                        thisClass.setVisible(true);
                        SystemInfoWindow window = new SystemInfoWindow(thisClass);
                        window.setMessage("System shutdown in progress ... lot sof atatarte athis tis a sa logoint of tesxt it keeps going and going and going thsoreoiat afsjkjslakjs fshafhdskrjlkjsdfj");
                        window.setVisible(true);
         //     ------------------------  Inner Classes ---------------------
         static class Test extends JFrame {
              private JPanel jContentPane = null;
               * This is the default constructor
              public Test() {
                   super();
                   initialize();
               * This method initializes this
               * @return void
              private void initialize() {
                   this.setSize(300, 200);
                   this.setContentPane(getJContentPane());
                   this.setTitle("JFrame");
               * This method initializes jContentPane
               * @return javax.swing.JPanel
              private JPanel getJContentPane() {
                   if (jContentPane == null) {
                        jContentPane = new JPanel();
                        jContentPane.setLayout(new BorderLayout());
                   return jContentPane;
         //     ------------------------  Static Fields ---------------------
         private static final long serialVersionUID = -8602533190114692294L;
         //     ------------------------  Static Methods --------------------
         //     ------------------------  Public Fields ---------------------
         //     ------------------------  Non-Public Fields -----------------
         private JPanel jContentPane = null;
         private JTextPane textField = null;
         public SystemInfoWindow(JFrame frame) {
              super(frame);
              initialize();
              //setUndecorated(true);
              setLocationRelativeTo(frame);
              pack();
         //     ------------------------  Interface Implementations ---------
         //     ------------------------  Public Methods --------------------
         public void setMessage(String text){
              textField.setText(text);
              adjustSize();
         //     ------------------------  Non-Public Methods ----------------
         private void adjustSize(){
              Dimension oldSize = textField.getPreferredSize();
              textField.setPreferredSize(new Dimension(
                        oldSize.width, oldSize.height + 30));
              pack();
         //     ------------------------  Generated Code --------------------
          * This method initializes this
          * @return void
         private void initialize() {
              this.setSize(300, 200);
              this.setModal(true);
              this.setContentPane(getJContentPane());
              this.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowOpened(java.awt.event.WindowEvent e) {
                        //setLocationRelativeTo(MsgLibGlobals.parent);
                        pack();
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(new BorderLayout());
                   jContentPane.setMaximumSize(new java.awt.Dimension(50,2147483647));
                   jContentPane.add(getTextField(), java.awt.BorderLayout.CENTER);
              return jContentPane;
          * This method initializes textField     
          * @return javax.swing.JTextPane     
         private JTextPane getTextField() {
              if (textField == null) {
                   textField = new JTextPane();
                   textField.setEditable(false);
                   textField.setMaximumSize(new java.awt.Dimension(20,2147483647));
              return textField;
    }Message was edited by:
    BaltimoreJohn

  • How to add new line wrapping rule?

    Hi all,
    I have a question about line wrapping condition of Java editor of JDeveloper.
    JDev has some predefined rules for it and I can change them from preference.
    But can I add a new rule?
    I'd like to place conditional operators such as "&&" or "||" at head of line.
    For example, as below.
    if (values[0].length() > 2
    && values[1].length() == 3
    || values[2].length() < 10
    && values[3].length() == 0) {
    JDev doesn't seem to have the predefined rule about conditional operators.
    So I'd like to know if I can add new one.
    My Jdeveloper is 11.1.1.6.0.
    Thanks,
    Atsushi

    Atsushi,
    I don't think you can add a new rule there.
    However, how about setting Line Wrapping->Binary Operators and Assignments to Always? Your code would then look like
           if (values[0].length() >
                2 &&
                values [1].length() ==
                3 ||
                values [2].length() <
                10 &&
                values [3].length() ==
                0 ) {
            }-Arun

  • Line wrapping and scrolling in JPanel

    Hello,
    I've got an empty JPanel to which I want to add an (unknown) number of JLabels. Each JLabel has a text which is just one word. When my program is adding JLabels to the JPanel, I want it to have the same behaviour as a normal text editor: when a line is full, the next line gets filled (line wrapping).
    If I just keep adding JLabels to a JPanel of a fixed size with .add(), there's no line wrapping. I tried it by giving the JPanel a fixed size, flowLayout and nesting it within a JScrollPane, but it keeps filling one long line, instead of jumping to the next one.
    Any obvious solutions??
    Thanks
    Mark

    well this depends on how your layout is build, you should post some code so we can see what your trying to do.
    For example if your JPanel is the Frame's main panel, fixing a MaximumSize or PreferredSize wont have any effect, it will grow as big as you defined the JFrame size.
    If you have only a JPanel with a max size of 200,300 in a JFrame with a size of 800,600, it will grow to 800,600.
    You could create a BoxLayout with X axis, then insert an HorizontalStruts, insert your JPanel and another Horizontal Struts(Box.createHorizontalStrut(int width) ) to force the JPanel to be smaller than the JFrame.
    I did not test this a lot, but it seams to work
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test {
      public static MyFrame frame ;
      public static void main(String[] args) {
        frame = new MyFrame();
        frame.show(true);
        frame.pack();
      public static class MyFrame extends JFrame {
        JLabel a, b, c, d, e, f, g, h, i, j, k ;
        public MyFrame(){
          super();
          JPanel sizeLimiter = (JPanel)this.getContentPane();
          sizeLimiter.setLayout(new BoxLayout(sizeLimiter, BoxLayout.X_AXIS));
         // sizeLimiter.setPreferredSize(new Dimension(800,600));
          JPanel mainPanel = new JPanel();
          mainPanel.setLayout(new FlowLayout());
          mainPanel.setPreferredSize(new Dimension(400,300));
          mainPanel.setMinimumSize(new Dimension(400,300));
          a = new JLabel("this is sample test ");
          b = new JLabel("to demonstrate an example ");
          c = new JLabel("of simple a flow layout ");
          d = new JLabel("which is wrapping ");
          e = new JLabel("when it reaches the end ");
          f = new JLabel("of a line. ");
          g = new JLabel("Set the maximum size of the panel ");
          h = new JLabel("And it should work ");
          i = new JLabel("If it doesnt post your code so we can");
          j = new JLabel("check it out to see whats wrong ");
          k = new JLabel("sincerly yours, Jf Beaulac ");
          mainPanel.add(a);
          mainPanel.add(b);
          mainPanel.add(c);
          mainPanel.add(d);
          mainPanel.add(e);
          mainPanel.add(f);
          mainPanel.add(g);
          mainPanel.add(h);
          mainPanel.add(i);
          mainPanel.add(j);
          mainPanel.add(k);
          // Fix some "margins"
          sizeLimiter.add(Box.createHorizontalStrut(200));
          // Squeeze the panel
          sizeLimiter.add(mainPanel);
          sizeLimiter.add(Box.createHorizontalStrut(200));
        protected void processWindowEvent(WindowEvent e) {
          super.processWindowEvent(e);
          if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            this.dispose();
    }Regards,
    Jf Beaulac

  • Line wrap in JTextField...

    Hi everyone..
    I noticed that JAVA recognizes the line wrap in the JTextField if i paste a text with 2 lines....the text in the component appears with 2 lines because of the line wrap...
    how can i solve this?? i don�t want that the line wrap is showed in my component...
    thanx

    The previous post suggested to create your own Document and prevent all newline characters from being added to the Document. Here is a link to the Swing tutorial on "General Rules for Using Text Components" which explains what a Document is and how to add a custom Document to you JTextField:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

  • Code Style - Line Wrapping - JSPX files

    JDeveloper 11.1.1.0.2
    I've got my Line Wrapping Line Width set to 180 and this works for my Java code but not for my JSPX files, which continue to break at 80 columns. In previous releases of JDeveloper my JSPX code would also wrap at 180, but I cannot remember what I did to make that happen. Can anyone give me a hint?
    Thanks, Mark

    Hi Mark,
    JDeveloper 11.1.1.0.2
    when I set Tools / Preferences / Code Editor / Display / Right Margin Column to 180 my line is on the same position also in jspx files
    regards,
    Branislav

  • Is there any function make lwuit - List line wrapping?

    Is there any function make lwuit - List line wrapping when the string is too long to display?
    Please Help~
    Thanks a lot.

    did you check LWUIT [API documentation|https://lwuit.dev.java.net/nonav/javadocs/index.html] or their forum?

  • HTMLEditorKit and line wrapping

    If you feed some HTML to an HTMLEditorKit and then ask for the text back, HTMLEditorKit formats the text for you and, in particular, breaks it into smaller lines as it deems necessary. This can be very inconvenient, because you may end up with white space in unexpected places.
    Does anybody know of a way to prevent HTMLEditorKit from line wrapping?
    Here is a little program which demonstrates what I am talking about...
    import java.io.StringReader;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLEditorKit;
    public class LineWrap {
        public static void main(String[] args) {
            String text = "<html><body>This is some <b>HTML</b> text.  It is all " +
                "on a single line, unless somebody takes the initiative to wrap " +
                "it into several lines.</body></html>";
            try {
                HTMLEditorKit kit = new HTMLEditorKit();
                HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
                kit.read(new StringReader(text), doc, 0);
                kit.write(System.out, doc, 0, doc.getLength());
            } catch (Exception exc) {
                exc.printStackTrace();
    }The output looks like this:
    <html>
      <head>
      </head>
      <body>
        This is some <b>HTML</b> text. It is all on a single line, unless somebody
        takes the initiative to wrap it into several lines.
      </body>
    </html>

    I have no idea about it, but does this help?
    http://forum.java.sun.com/thread.jspa?threadID=298090
    Yes it does! You can prevent line wrapping by subclassing HTMLWriter and overriding the method canGetWrapLines() so that it always returns false.
    Thank you.

  • Multiple StringItems and line wrapping

    Hello!
    Why is it, that StringItems, that have to be line wrapped because of their length, cause the following StringItems to start at a new line after the preceding one, even if there is still enough room?
    Tested with WTK 2.5.1 (Qwerty Device)
    Here's an example:
    * ExampleMidlet.java
    * Created on 1. November 2007, 18:30
    package hello;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    * @author rp
    * @version
    public class ExampleMidlet extends MIDlet {
    public void startApp() {
    StringItem s1,s2,s3;
    Form form = new Form("Example");
    s1 = new StringItem(null,"That's just an example for a very long line, which has probably to be wrapped and a ");
    s1.setLayout(Item.LAYOUT_2);
    form.append(s1);
    s2 = new StringItem(null,"hyperlink");
    s2.setLayout(Item.LAYOUT_2);
    form.append(s2);
    s3 = new StringItem(null,", which is followed by even more Text");
    s3.setLayout(Item.LAYOUT_2);
    form.append(s3);
    Display.getDisplay(this).setCurrent(form);
    public void pauseApp() {
    public void destroyApp(boolean unconditional) {
    Some real devices do this right, starting an item where the
    preceding one stops. Unfortunately lot's of others don't (following
    the WTK)
    Please!
    Do I really have to generate zillions of One-Word-StringItems in order to avoid ugly line wrapping ?
    cheers, Roland

    Please!
    Do I really have to generate zillions of One-Word-StringItems in order to avoid ugly line wrapping ?How about just one StringItem containing the entire text? Or would that create other problems?I have text with hyperlinks in between. That's why I cannot put it in one single StringItem.
    Device fragmentation. Nothing anyone can do about it.I don't think, device fragmentation is an argument here:
    Why should there be a layout directive like Item.LAYOUT_NEWLINE_BEFORE/AFTER
    if you shouldn't also have the possibility to have no line wrap at all?
    Here's what the API says:
    A row break occurs before an item if any of the following conditions occurs:
    the previous item has a row break after it;
    it has the LAYOUT_NEWLINE_BEFORE directive; or
    it is a StringItem whose contents starts with "\n";
    it is a ChoiceGroup, DateField, Gauge, or a TextField, and the LAYOUT_2 directive is not set; or
    this Item has a LAYOUT_LEFT, LAYOUT_CENTER, or LAYOUT_RIGHT directive that differs from the Form's current alignment.
    A row break occurs after an item if any of the following conditions occurs:
    it is a StringItem whose contents ends with "\n"; or
    it has the LAYOUT_NEWLINE_AFTER directive; or
    it is a ChoiceGroup, DateField, Gauge, or a TextField, and the LAYOUT_2 directive is not set.
    Neither there's a directive, that differs from the Form's current alignment, nor there's a newline in
    the StringItem, etc.
    So I guess,there shouldn't be a row break here.
    Thanks, Roland

  • Line wrap.

    Hey guys, i am trying to learn how to do word wrap on Jtextareas....i found this code by surfing this site, i implemented it into my code but the line wrap had no effect.
    I think i have to set a value somewhere to say after 200chars do a line wrap and go to next line. But i cant find how to do this anywhere.
    Will anyone please tell me how to set how many chars can be on each line?
    (sorry if this question isnt specific enough, but i am stuck for aboout 2 hours on this problem)
    JTextArea textArea = new JTextArea(
        "This is an editable JTextArea " +
        "that has been initialized with the setText method. "
    textArea.setFont(new Font("Serif", Font.ITALIC, 16));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);

    Hi guys still trying to figure out that new line thingy...I am getting close, but i have an error that i cant solve, can any see what is wrong, i have pasted the error at the end..
    here is my code:
    JTextArea resourceDescField = new JTextArea();
         JScrollPane resourceDescFieldScrollPane = new JScrollPane(resourceDescField);
    resourceDescField.getDocument().addDocumentListener(new MyDocumentListener());
            resourceDescField.getDocument().putProperty("name", "Text Area");
    class MyDocumentListener implements DocumentListener
              String newline = "\n";
              public void insertUpdate(DocumentEvent e)
                  updateLog(e, "inserted into");
              public void removeUpdate(DocumentEvent e)
                  updateLog(e, "removed from");
              public void changedUpdate(DocumentEvent e)
              public void updateLog(DocumentEvent e, String action)
                  Document doc = (Document)e.getDocument();
                  int changeLength = e.getLength();             
                   if(changeLength > 150);
                   resourceDescField.append(resourceDescField.getText()+newline);
         }here is my error:
    Exception occurred during event dispatching:
    java.lang.IllegalStateException: Attempt to mutate in notification
    at javax.swing.text.AbstractDocument.writeLock(Unknown Source)
    at javax.swing.text.AbstractDocument.insertString(Unknown Source)
    at javax.swing.JTextArea.append(Unknown Source)
    at UpdateResource$MyDocumentListener.updateLog(UpdateResource.java:191)
    at UpdateResource$MyDocumentListener.insertUpdate(UpdateResource.java:17
    6)
    at javax.swing.text.AbstractDocument.fireInsertUpdate(Unknown Source)
    at javax.swing.text.AbstractDocument.insertString(Unknown Source)
    at javax.swing.text.JTextComponent.replaceSelection(Unknown Source)
    at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerform
    ed(Unknown Source)

  • How to prevent automatic line wrapping in a JEditorPane

    I have added a JEditorPane inside a JScrollPane which is inturn is added inside a JPanel with a GridLayout.
    While JEditorPane is loaded with an HTML page or a html file is read into it with an HTMLDocument the longer lines are geting wrapped automatically to the next line when the display area of the parent component of the JPanel where the original JScrollPane is held (like the JFrame or JSplitPane etc.)
    It doesn't help even after seeing a preferredsize/maximumSize or minimumSize
    of the JEditorPane (b'cos it defaults to some other size which i'ven't set at all).
    The horizontal scrollbar apperas only the when the the JEditorPanes size is reduced lesser than its defult size which has been set (probably by the layout manager).
    I want to get rid of this behaviour of the JEditorPane such that horizontal Scollbar should apper as soon as the user reduce the size of the window displaying the above component hierarchy (parent container->JScrollPane->JEditorPane) and no line wrapping occurs.
    Note : 1. JEditorPane doesn'y have linewrapping API like JTextArea
    2. Its default and automatic linewrapping behaviour is conforming
    with word line wrapping where lines are broken at the end of a
    word which can be fully accomodated.

    I have added a JEditorPane inside a JScrollPane which is inturn is added inside a JPanel with a GridLayout.
    While JEditorPane is loaded with an HTML page or a html file is read into it with an HTMLDocument the longer lines are geting wrapped automatically to the next line when the display area of the parent component of the JPanel where the original JScrollPane is held (like the JFrame or JSplitPane etc.)
    It doesn't help even after seeing a preferredsize/maximumSize or minimumSize
    of the JEditorPane (b'cos it defaults to some other size which i'ven't set at all).
    The horizontal scrollbar apperas only the when the the JEditorPanes size is reduced lesser than its defult size which has been set (probably by the layout manager).
    I want to get rid of this behaviour of the JEditorPane such that horizontal Scollbar should apper as soon as the user reduce the size of the window displaying the above component hierarchy (parent container->JScrollPane->JEditorPane) and no line wrapping occurs.
    Note : 1. JEditorPane doesn'y have linewrapping API like JTextArea
    2. Its default and automatic linewrapping behaviour is conforming
    with word line wrapping where lines are broken at the end of a
    word which can be fully accomodated.

  • Line wrap in JTextPane

    I didn't see a setLineWrap(boolean) method in JTextPane (as you can tell from my previous posts I'm having trouble going from a JTextArea to a text component that can format text). How would I force it to line wrap like a JTextArea would if you called
    tp.setLineWrap(true);
    tp.setWrapStyleWord(true); ?
    I've set the JTextPane in a JScrollPane, so I'm worried it will not wrap.
    thanks for the info.

    I just finished some testing and it seems the the line wrapping is set to the way I wanted by default, ie by just like I had called the above methods on a JTextField
    thanks

Maybe you are looking for