Force word wrap in JTextPane (using HTMLEditorKit)

Hi!
I have a JTextPane on a JScrollPane inside a JPanel. My text pane is using HTMLEditorKit.
I set the scrolling policies of my JScrollPane to: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED & JScrollPane.HORIZONTAL_SCROLLBAR_NEVER.
I did not find in JTextPane�s API any relevant property I can control word-wrapping with (similar to JTextArea�s setLineWrap) and I have tried a few things to force word-wrapping but nothing worked...
What happens is my text is NOT being wrapped (even though there is no horizontal scrolling) and typed characters (it is an enabled editable text componenet) are being added to the same long line�
I�d like to force word-wrapping (always) using the vertical scroll bar whenever the texts extends for more then one (wrapped) line.
Any ideas?
Thanks!!
Message was edited by:
io1

Your suggestion of using the example only holds if it fits the requirements of the featureDid your questions state anywhere what your requirement was?
You first questions said you had a problem, so I gave you a solution
You next posting stated what your where currently doing, but it didn't say it was a requirement to do it that way. So again I suggested you change your code to match the working example.
Finally on your third posting you state you have some server related issues causing the requirement which I did not know about in my first two postings.
State your problem and special requirments up front so we don't waste time quessing.
I've used code like this and it wraps fine:
JTextPane textPane = new JTextPane();
textPane.setContentType( "text/html" );
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
HTMLDocument doc = (HTMLDocument)textPane.getDocument();
textPane.setText( "<html><body>some long text ...</body></html>" );
JScrollPane scrollPane = new JScrollPane( textPane );If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Similar Messages

  • Word Wrap in JTextPane

    I'm working with just a JTextPane, no JScrollPane around it or anything.
    I would like the JTextPane to use word wrap, but it looks like by default it does not. I looked through some API stuff and tutorials and found nothing on the subject.
    The code is trivial and pointless to post right now. All I dd was make a JTextPane via new JTextPane() (no arguments or anything) and type in it enough to see if it word wrapped and it didn't.
    Is there a way to enable word wrap on JTextPanes?

    no JScrollPane around it or anything.The scroll pane forces the wrapping because it enforces the width limit. Otherwise there is no limit.
    You can use setPreferredSize(...) to force the width, but then that also restricts the height.
    Reply 6 of this posting may give you some ideas.

  • Preventing word wrapping in JTextpane

    I'm stumped about preventing word wrapping in a JTextpane. Any suggestions?

    Word wrapping occurs when the text hits the "edge" of the JTextPane, as (ordinarily) defined by the parent component of the JTextPane. But if you view the JTextPane in a JScrollPane, the edge is defined by the JTextPane itself rather than the parent component. So if the JTextPane is wide enough, the text will not wrap (you may or may not need to call setSize on the JTextPane). You can turn off the horizontal scrollbar if you like, using JScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER), which would cause any text wider than the JScrollPane parent to simply be clipped off.
    A code sample is usually available at http://www.radecke.ch/exscrolltextpane.htm (the site appears to be down at the moment).

  • Word wrap with JTextPane

    Ok, at the risk of sounding stupid: How do you turn off the word wrap on a JTextPane.
    Thanks in advance, Ed

    ...and I forgot setSize public class NonScrollingPane extends JTextPane { 
      public NonScrollingPane() {   
        super(); 
      public boolean getScrollableTracksViewportWidth() {
        return false; 
      public void setSize(Dimension d) {
        if(d.width < getParent().getSize().width) {
          d.width = getParent().getSize().width;
        super.setSize(d);
    }Ulrich

  • Word wrapping at JTextPane boundaries

    Hi ! I have two problems related to JTextPane -
    1. I want to wrap words which are larger than the width of JTextPane so that it may remain visible inside the fixed boundaries.
    2. if there is an image and it can not be displayed in the same line in continuation of text then it should be displayed in the next line.
    All images that i have used have less width than that of JTextPane.
    Both these problems may be related or different, I dont know how to solve these problems.
    Please suggest any solution.

    Till now I am able to find the height of JTextPane after inserting some text by creating a dummy JTextPane
    and calling the method getPrefferedSize().height
    this wraps text correctly at word boundaries but i want it to be wrapped according to word boundaries and
    textpane boundaries both
    actually I am developing a chat application in which I have to show message from other person
    and if there is some text like ": )", ": D" etc then i want to show smileys :), :D in the place of these substrings
    I can insert text and replace the text with images by using StyledDocument's insert function
    but if i simply replace the text with images then the images are shown in the same line and wrapping doesn't work
    hence some part of images are not visible in the JTextPane
    as shown in the links http://www.facebook.com/photo.php?fbid=193222607456431&set=a.193222600789765.36992.100003060781951&type=1&ref=nf
    and http://www.facebook.com/photo.php?fbid=193225164122842&set=a.193222600789765.36992.100003060781951&type=1&ref=nf
    here link 1 shows the problem of partial display of image
    and link 2 shows the problem of inserting text that is larger than the width of the JTextPane
    And i want that whatever is inside the JTextPane should be shown inside the boundaries of it, I don't want to add a
    horizontal scrollbar !!!!!
    hope you got the problem, please provide some help !

  • Word wrapping with JTextPane and styleDocument

    Hello,
    Can someone help me with the following problem.
    I have a JTextPane where i add a styledDocument.
    If i fill this with text it doen't word-warp the text!
    import javax.swing.JTextPane;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.Style;
    import javax.swing.text.StyledDocument;
    public class LogField extends JTextPane implements LogFileTailerListener{
         public static StyledDocument doc;
         private LogFileTailer tailer;
         private TextStyles styles;
         public LogField(){
              this.setEditable(false);
              this.setContentType("text/html");
              doc = (StyledDocument)this.getDocument();
              styles = new TextStyles();
              tailer = new LogFileTailer( LogPanel.logFileName, 1000, true );
              tailer.addLogFileTailerListener( this );
             tailer.start();          
         public void addText(String text, Style style){     
               try {
                  text = text + System.getProperty("line.separator");
                   doc.insertString(doc.getLength(), text, style);
              } catch (BadLocationException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              this.setCaretPosition(doc.getLength());
         @Override
         public void newLogFileLine(String line) {
                addText(line,styles.getDefaultStyle());
    }

    Since you are simply appending text to the Document you should not be using a type of "text/html".
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.

  • JEdtiorPane/HTMLEditorKit word wrapping problems

    Hi,
    I have a JFrame component that has a splitPane, on the left side is a JTree and the right side has a JEditorPane that has it's content updated with HTML using a method to generate the HTML via the setText() method . (no url, and no html file)
    The searching I did indicates that word wrapping is the default behavior, and I saw a lot of posts from people trying to get rid of the word wrapping, but it isn't wrapping at all for me. I get the horizontal scroll bar.
    I had the same problem using a JTextPane...anyone know how to wrap text?
    here's the relevant code:
    descriptionPanel = new JPanel(new BorderLayout());
              descriptionEditorPane = new JEditorPane();
              HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
              descriptionEditorPane.setEditorKit(htmlEditorKit);
              descriptionEditorPane.setSize(new Dimension(610,800));
              descriptionEditorPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              descriptionPanel.add(descriptionEditorPane);

    Did you place the components into scroll panes and then put those into the split pane?
    If so, then I guess that calling setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) on the editor pane's scroll pane might solve your problem.

  • JTextPane always word wrapping

    I'm having problems convincing a JTextPane not to word wrap. My JTextPane is contained in a JScrollPane. I've looked and found out how to turn off word wrap in a JTextArea, and applied suggestions about turning horizontal scrollbars on, but it doesn't work. My JTextPane keeps wrapping text regardless of what I do to it. It seems to me that, since the JTextPane is more "sophisticated" than a JTextArea, I should be able to do this. Any suggestions?
    Matt

    Hi,
    overwrite the following method in your JTextPane-subclass
    public boolean getScrollableTracksViewportWidth() { return false;  }this works, if you use the scrollbar-policies below - I use that in a mud-client, returning false if I want it not to wrap and returning true, if I want it to wrap.
    I use the following on the JScrollPane, the JTextPane is in (assuming sp is your JScrollPane)
    sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);Hope, this helps
    greetings Marsian

  • Word wrapping incorrect inside JTextPane on MAC 0.5/10.4 and Linux OS

    Hello java-dev team,
    In my application, I am using JTextPane as a text editor to create RTF text. The problem I observed with the JTextPane on MAC OS and Linux OS flavors (I tested on Ubuntu 8.04) is: whenever I am changing any of the text property (font color, font name, font style like bold, italic or underline) and then enter the characters without providing space, the whole word gets wrapped to the next line from the point where exactly the property change starts i.e. the new formatted text is jumped to the next line from the starting point of formatting.
    My requirement is, as I am not adding any space character while changing the property, the characters should be entered in the sequence and should come to new line as per normal word-wrap rule.
    Can anybody help me out in this regards with some solution as it’s a very urgent requirement?
    Below I am also providing the sample code to check the behavior. There is no dynamic facility to change the property in the below code but I am providing the text with multiple formatting settings through code itself. To reproduce the above issue, just type the characters using keyboard in between characters with changed text properties and you can see the whole word jumping to new line.
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.text.MutableAttributeSet;
    import javax.swing.text.SimpleAttributeSet;
    import javax.swing.text.StyleConstants;
    import javax.swing.text.StyledDocument;
    import javax.swing.text.StyledEditorKit;
    public class TestWrapping {
         JScrollPane scroll;
         JTextPane edit;
         public TestWrapping()  throws Exception {
              final JFrame frame=new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              edit=new JTextPane()
                   public void setSize(Dimension d)
                        if (d.width < getParent().getSize().width)
                             d.width = getParent().getSize().width;
                        super.setSize(d);
                   public boolean getScrollableTracksViewportWidth()
                        return false;
              edit.setPreferredSize(new Dimension(150,150));
              edit.setSize(150,150);
              edit.setEditorKit(new StyledEditorKit());
              scroll=new JScrollPane(edit);
              edit.getDocument().insertString(0,"11111111111111222222222222222222222222222222222222222",null);
              MutableAttributeSet attrs=new SimpleAttributeSet();
              StyleConstants.setBold(attrs,true);
              ((StyledDocument)edit.getDocument()).setCharacterAttributes(30,5,attrs,false);
              StyleConstants.setUnderline(attrs,true);
              ((StyledDocument)edit.getDocument()).setCharacterAttributes(35,5,attrs,false);
              StyleConstants.setFontSize(attrs,25);
              ((StyledDocument)edit.getDocument()).setCharacterAttributes(40,5,attrs,false);
              frame.getContentPane().add(scroll);
              frame.setBounds(0,0,150,150);
              frame.show();
         public static void main(String[] args) throws Exception {
              new TestWrapping();
    }The same functionality works fine on Windows XP and problem is observed on MAC OS 10.4/10.5, Ubuntu 8.04. I am using jdk1.5 on both the platforms. I tested using jdk 6.0 on Ubuntu 8.04, and the problem is easily reproducible. I placed a query in the respective OS forums also but did not receive any replies. I also searched the sun’s bug database, but could not find any bug addressing the mentioned problem correctly. I also logged issue at bugs.sun.com and was assigned internal review ID of 1480019 for this problem.
    If you need any additional information, please let me know.
    Thanks in advance.
    Regards,
    VPKVL

    VPKVL wrote:
    Hi All,
    Just want to update that when I checked this issue with JDK1.6 on Ubuntu 8.04, I am unable to reproduce the issue. Everything works as expected. But problem continues on MAC 10.5. So can anybody help me out in coming out of this issue on MAC 10.5.
    Thanks in advance.The only thing I can suggest is that you open a bug (radar) with apple ( developer.apple.com ), and then wait at least 12 months for Apple to get around to fixing it :s

  • I have been using a Google moderated group with a robo receptor which suddenly turns down my message submission because it won't "word wrap" correctly. I have made no changes in my messages to the forum so the problem must be with my end. Any Ideas?

    I have been using a Google moderated group with a robo receptor which suddenly turns down my message submission because it won't "word wrap" correctly. I have made no changes in my messages to the forum so the problem must be with my end. Any Ideas?

    I have been using a Google moderated group with a robo receptor which suddenly turns down my message submission because it won't "word wrap" correctly. I have made no changes in my messages to the forum so the problem must be with my end. Any Ideas?

  • Resizing ListCellRenderers using JTextArea and word wrap

    Hi,
    I'm trying to create a ListCellRenderer to draw nice cells for a JList. Each cell has a one line title and a description of variable length. So, I create a custom ListCellRenderer, which consists of a JPanel containing a JLabel for the title and a JTextArea for the description. I set the JTextArea to do wrapping on word boundried and it all almost works.
    But, the list cells don't resize to accomodate the variable height of the cells. They show only 1 line for the title and 1 line for the description.
    I have seen a few threads relating to this including the article, "Multi-line cells in JTable in JDK 1.4+" in the Java Specialists' Newsletter, which seems to do a similar trick for JTables. But so far nothing I've tried works.
    Curiously, using println debugging, my getListCellRenderer method seems to get called for each cell twice while my GUI is being drawn. It looks to me like the TextUI view that draws the JTextArea seems to do the word wrapping after the first set of getListCellRenderer calls. But, it's the first set of calls that seems to establish the layout of the list.
    Any help would be appreciated. I've pulled out quite enough hair over this one.
    -chris
    package bogus;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Font;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.*;
    public class CellRendererTest {
         public static void main(String[] args) {
              final CellRendererTest test = new CellRendererTest();
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        test.createGui();
         public void createGui() {
              JFrame frame = new JFrame("Testing Bogus ListCellRenderer");
              JList list = new JList(createBogusListItems());
              list.setCellRenderer(new MyListCellRenderer());
              frame.add(list);
              frame.setSize(200, 400);
              frame.setVisible(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         private MyListItem[] createBogusListItems() {
              List<MyListItem> items = new ArrayList<MyListItem>();
              items.add(new MyListItem("First item", "This is a nice short description."));
              items.add(new MyListItem("Another one", "This is a longer description which might take up a couple of lines."));
              items.add(new MyListItem("Next one", "This is a ridiculously long description which is total gibberish." +
                        "Blah blah blabber jabber goo. Blither blather bonk. Oink boggle gaggle ker-plunk."));
              items.add(new MyListItem("No Desc", null));
              items.add(new MyListItem("Last one", "Boink!"));
              return items.toArray(new MyListItem[items.size()]);
         static class MyListCellRenderer extends JPanel implements ListCellRenderer {
              private JLabel title;
              private JTextArea desc;
              // hack to see if this is even possible
              private static int[] rows = {1, 2, 3, 0, 1};
              public MyListCellRenderer() {
                   setLayout(new BorderLayout());
                   setBorder(BorderFactory.createEmptyBorder(6, 4, 6, 4));
                   setOpaque(true);
                   title = new JLabel();
                   title.setFont(new Font("Arial", Font.ITALIC | Font.BOLD, 11));
                   add(title, BorderLayout.NORTH);
                   desc = new JTextArea();
                   desc.setFont(new Font("Arial", Font.PLAIN, 9));
                   desc.setOpaque(false);
                   desc.setWrapStyleWord(true);
                   desc.setLineWrap(true);
                   add(desc, BorderLayout.CENTER);
              public Component getListCellRendererComponent(JList list, Object value,
                        int index, boolean isSelected, boolean cellHasFocus) {
                   MyListItem item = (MyListItem)value;
                   title.setText(item.title);
                   if (item.description != null && item.description.length() > 0) {
                        desc.setText(item.description);
                        desc.setVisible(true);
                   else {
                        desc.setVisible(false);
                   // uncomment next line to to somewhat simulate the effect I want (hacked using the rows array)
                   // desc.setRows(rows[index]);
                   if (isSelected) {
                        setBackground(list.getSelectionBackground());
                        setForeground(list.getSelectionForeground());
                   else {
                        setBackground(list.getBackground());
                        setForeground(list.getForeground());
                   return this;
         static class MyListItem {
              String title;
              String description;
              public MyListItem(String title, String description) {
                   this.title = title;
                   this.description = description;
    }

    This seems to work
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Insets;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.text.View;
    public class CellRendererTest {
         int WIDTH = 220;
         public static void main(String[] args) {
              final CellRendererTest test = new CellRendererTest();
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        test.createGui();
         public void createGui() {
              JFrame frame = new JFrame("Testing Bogus ListCellRenderer");
              JList list = new JList(createBogusListItems());
              final MyListCellRenderer renderer = new MyListCellRenderer();
              list.setCellRenderer( renderer );
              JScrollPane listScrollPane = new JScrollPane(list);
              frame.add(listScrollPane);
              frame.setSize(WIDTH, 400);
              frame.setVisible(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         private MyListItem[] createBogusListItems() {
              List<MyListItem> items = new ArrayList<MyListItem>();
              items.add(new MyListItem("First item", "This is a nice short description."));
              items.add(new MyListItem("Another one", "This is a longer description which might take up a couple of lines."));
              items.add(new MyListItem("Next one", "This is a ridiculously long description which is total gibberish." +
                        "Blah blah blabber jabber goo. Blither blather bonk. Oink boggle gaggle ker-plunk."));
              items.add(new MyListItem("No Desc", null));
              items.add(new MyListItem("Last one", "Boink!"));
              items.add(new MyListItem("Ooops this one breaks things by being longer than my fixed width", "Blabber babble gibber flipper flop."));
              return items.toArray(new MyListItem[items.size()]);
         static class MyListCellRenderer extends JPanel implements ListCellRenderer {
              public JLabel title;
              public JTextArea desc;
              Color altColor = new Color(0xeeeeee);
              public MyListCellRenderer() {
                   setLayout(new BorderLayout());
                   setBorder(BorderFactory.createEmptyBorder(6, 4, 6, 4));
                   setOpaque(true);
                   title = new JLabel();
                   title.setFont(new Font("Arial", Font.ITALIC | Font.BOLD, 11));
                   add(title, BorderLayout.NORTH);
                   desc = new JTextArea();
                   desc.setFont(new Font("Arial", Font.PLAIN, 9));
                   desc.setOpaque(false);
                   desc.setWrapStyleWord(true);
                   desc.setLineWrap(true);
                   add(desc, BorderLayout.CENTER);
              public Component getListCellRendererComponent(JList list, Object value,
                        int index, boolean isSelected, boolean cellHasFocus) {
                   Insets insets = desc.getInsets();
                int rendererLeftRightInsets = insets.left + insets.right + 8;  // 8 from panel border
                int topDownInsets = insets.top + insets.bottom;
                int listWidth = list.getWidth();
                int viewWidth = listWidth;
                   int scrollPaneLeftRightInsets = 0;
                   JScrollPane scroll = (JScrollPane) SwingUtilities.getAncestorOfClass( JScrollPane.class, list );
                   if ( scroll != null && scroll.getViewport().getView() == list ) {
                        Insets scrollPaneInsets = scroll.getBorder().getBorderInsets(scroll);
                     scrollPaneLeftRightInsets = scrollPaneInsets.left + scrollPaneInsets.right;
                     listWidth = scroll.getWidth() - scrollPaneLeftRightInsets;
                     JScrollBar verticalScrollBar = scroll.getVerticalScrollBar();
                     if (verticalScrollBar.isShowing()) {
                         listWidth -= verticalScrollBar.getWidth();
                     viewWidth = listWidth - rendererLeftRightInsets;
                   MyListItem item = (MyListItem)value;
                   title.setText(item.title);
                   if (item.description != null && item.description.length() > 0) {
                        desc.setText(item.description);
                        desc.setVisible(true);
                        View rootView = desc.getUI().getRootView(desc);
                     rootView.setSize( viewWidth, Float.MAX_VALUE );
                    float yAxisSpan = rootView.getPreferredSpan(View.Y_AXIS);
                        Dimension preferredSize = new Dimension( viewWidth, (int)yAxisSpan + topDownInsets );
                        desc.setPreferredSize( preferredSize );
                   } else {
                        desc.setVisible(false);
                   title.setPreferredSize( new Dimension( viewWidth, title.getPreferredSize().height ) );
                   // uncomment next line to to somewhat simulate the effect I want (hacked using the rows array)
                   //desc.setRows(rows[index]);
                   if (isSelected) {
                        setBackground(list.getSelectionBackground());
                        setForeground(list.getSelectionForeground());
                   else {
                        if (index % 2 == 0)
                             setBackground(altColor);
                        else
                             setBackground(list.getBackground());
                        setForeground(list.getForeground());
                   return this;
         static class MyListItem {
              String title;
              String description;
              public MyListItem(String title, String description) {
                   this.title = title;
                   this.description = description;
    }

  • pre div style="word-wrap:break-word" long text /div /pre doesn't force wrap

    <pre><div style="word-wrap:break-word">long text</div></pre> works in IE9 but not FireFox 31. Actual returns do wrap text but the text of long paragraphs extends outside the <div>, despite the word-wrap:break-word style. Maybe I'm expecting too much interpretation from <pre>? But I am thinking if IE can handle this, perhaps FireFox could too?

    Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The helpers over there are more knowledgeable about web page development issues with Firefox.
    http://forums.mozillazine.org/viewforum.php?f=25
    You'll need to register and login to be able to post in that forum.

  • JEditorPane word wrap problems

    I am using a JEditorPane in a chat window that is used, like instant messenger, between two clients. The ability to insert icons and different fonts is available after setting the editor kit to an HTMLEditorKit. However, after using an HTMLEditorKit, the word wrapping is a bit funky in that the words are cut off when wrapping.
    Is there any way to get aroudn this while STILL using a JEditorPane (or something similar that can accept HTML?). I would be able to use JTextPane, which wraps correct (I believe...I'm trying to think back to my first implementation), but the icons begin to get tricky there. I know how to insert them, but if I have multiple icons, I would need to find all of the first occuring icons since the string needs to be printed immediately to the screen.
    Thanks for any help.

    I don't have an HTML document. Maybe you are mis-interpreting what I am trying to do :)
    I am implementing a simple instant messenger (much like AIM). Right now, I have a JEditorPane that is using an HTMLEditorKit to render HTML. This is used to display emoticons and also change the font and font color. So, the HTML I am generating is manually put in there in the code so text will show up differently - say, the senders name will be red and the recipient will be blue.
    Everything is working fine, except the text is wrapping and words are being cut off. In other words, this is happening:
    | This is an exa |
    | mple of some |
    | thing that is ha |
    | ppenning in m |
    | y chat window. |
    -----------------------

  • Word Wrap with a Vertical Grid

    I've got a vertical grid with my headers in the left column and descriptive text in the column immediately to the right.  I'd like to have the descriptive text word wrap but checking the word wrap box on the layout tab doesn't seem to have any effect.
    Any ideas?  I'm using 11.5 SP3

    I'm not sure if it will work with the iGrid in a vertical orientation, but have you tried setting the RowHeight to something like 20 or 30 instead of the default of 0?  This setting will auto adjust the grid lines based upon the font-size, but you may need to force it to a certain height in order for the wrapping to work.
    Regards,
    Jeremy

  • JLabel Word Wrap

    I'm building a simple chat application to work on my network programming skills. I ran into an issue that I can't quite find a solution to.
    I Have a JPanel inside of a JScrollPane, and inside of it JLabels with the messages received are added as they come. I would like the JLabels to wrap the text after it reaches a certain width. Here's the testing code I'm using for this:
    import java.awt.*;
    import javax.swing.*;
    class ChatBody {
         public static Container createChatBody() {
              JPanel body = new JPanel(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.BOTH;
              c.weightx = 1.0;
              c.weighty = 1.0;
              JPanel messages = new JPanel();
              JScrollPane messagesPane = new JScrollPane(messages);
              messagesPane.setPreferredSize(new Dimension(608, 478));
              messagesPane.setBorder(BorderFactory.createLineBorder(Color.black));
              messagesPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              JLabel messageOne = new JLabel("This is a label that I'm going to make really long to test the wrapping abilities of a JLabel/JPanel/JScrollPane. This needs to be really long so it will reach the end of the scroll pane and *hopefully* wrap on it's own, so I won't have to do any work =D");
              messages.add(messageOne);
              c.gridx = 0;
              c.gridy = 0;
              body.add(messagesPane, c);
              return body;
    }Please note I took some irrelevant code out.
    Is there a method or something to make JLabels word wrap? Or will I have to be creative and make something up?
    Edit: I don't know if this is relevant, but this is the class with the main() method:
    import java.awt.*;
    import javax.swing.*;
    class JavaChat {
         public static void createChatWindow() {
              JFrame frame = new JFrame("Java Chat");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setMinimumSize(new Dimension(800, 600));
              //frame.setJMenuBar();
              frame.getContentPane().add(ChatBody.createChatBody());
              frame.pack();
              frame.setVisible(true);
         public static void main(String args[]) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createChatWindow();
    }That's needed for anyone that needs to compile my code for some reason.
    Edited by: shadowayex on Dec 24, 2009 1:47 PM

    Wrapping is not support in a JLabel.
    Most people would use either a JTextArea or JTextPane which do support wrapping.

Maybe you are looking for

  • Steps to extract data from teradata to bw

    steps to extract data from teradata to bw

  • BLOBS (pdf, doc, bmp, jpg, gif, ppt, xls) to OS SERVER FILE

    Hi, I am using Oracle9i Enterprise Edition Release 9.2.0.6.0 on Unix (SUSE Linux and Solaris). I have a table which holds a blob which was loaded from a file. This file could be any of the above formats. I need to create a function which will create

  • BPS You have no authorization for the requested data

    We are implementing Hierarchy node based security for our BPS. When the user tries to display the planning layout, they get the error message "You have no authorization for the requested data " I have given authorization to the relavant Infocubes, al

  • Poker playing for money app

    I play poker throught pokerstars, seems cannot load an app or download the software to play poker on an Ipad, (first generation). What gives?

  • Flashplayer for nokia 5800

    i formated my nokia 5800 xpressmusic and realised that the explorer in version 60 doesn't have flashplayer and therefore some sites aren't working.. how could i install flashplayer