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.