0

I am trying to display some text as following format:

line1.append("ab         cdefg       hijk        ab          cdefg       hijk        ab          cdefg       hijk        ab          cdefg       hijk        ab          cdefg       hijk        ab          cdefg       hijk        ab          cdefg       hijk        Operating ");
line2.append(".............................................................................................................................................................................................................................................................. abcd . ");
line3.append("                                                                                                                                                                                                                                                              (efgh)  ");

display code:

    JTextPane area = new JTextPane() {
        @Override
        public boolean getScrollableTracksViewportWidth() {
            Component parent = getParent();
            ComponentUI ui = getUI();
            return parent != null ? (ui.getPreferredSize(this).width <= parent.getSize().width) : true;
        }
    };
    area.setText(textLines);
    area.setFont(new Font("COURIER", Font.PLAIN, 10));
    area.setEditable(false);
    JScrollPane scroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

line1 & line2 can be displayed properly, without wrapping which is what I expected; while once line3 is added into the text, wrapping happens.

i am using jdk7. any clues? thanks in advance.

EmilyR
  • 21
  • 3
  • Why did you tagged this question as java 7 ? isn't it rather 'java, swing' ? – André R. Aug 12 '15 at 07:23
  • well, honestly i did not test this on java 6, but i did notice [no text wrap textpane](https://tips4java.wordpress.com/2009/01/25/no-wrap-text-pane/), and [this bug from java 7](http://bugs.java.com/view_bug.do?bug_id=6539700). hence i was thinking this might be related to 7 as well. sorry for my assumption, and tag updated. – EmilyR Aug 13 '15 at 01:12
  • No harm meant! i just thought that the question will find people with swing knowledge easier if the question is tagged 'swing'. – André R. Aug 13 '15 at 07:07
  • did you see this stackoverflow question http://stackoverflow.com/questions/7156038/jtextpane-line-wrapping ? – André R. Aug 13 '15 at 07:08
  • yes, I saw that, but it didn't explain my situation. in my case, everything is what I expected if there are not too many spaces (e.g. line3 from code above). the display code is exactly the same. but wrapping happens when line3 is added. – EmilyR Aug 14 '15 at 06:08

0 Answers0