Results 1 to 3 of 3
Thread: JEditorPane and line wrapping
- 12-21-2012, 02:03 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 24
- Rep Power
- 0
JEditorPane and line wrapping
My JEditorPane doesn't wrap lines.
I try WordUtils.wrap(String text,int wrapLength) method. WordUtils (Commons Lang 2.5 API)
My problem is that I can't find wrapLength.
I try scrollPane.getViewport().getSize().width method to find wrapLength without results.
How can I find the wrapLength?
Is there another way for line wrapping?
- 12-21-2012, 02:11 PM #2
Re: JEditorPane and line wrapping
Since your question appears to be related to Apache Commons, I've moved the thread here from New to Java.
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem. Of course, only those members who have the Apache Commons package will be in a position to help.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-21-2012, 05:20 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 24
- Rep Power
- 0
Re: JEditorPane and line wrapping
@DarrylBurke
I am novice and I suppose that "New To Java" category is the best place to post.
Also I want to listen another solution except Appache Commons WordUtils.
This is not a complaint , I always respect the moderators, please do not get me wrong.
Anyway, I hoped that WordUtils.wrap(text) method will solve my problem but I was wrong.
This is my code and I put my own value to widthLength.
I press button and WordUtils.wrap(String text, int widthLength) is called but the text isn't wrapped correctly.
Sorry for my bad english.
Java Code:import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; import org.apache.commons.lang3.text.WordUtils; public class LineWrap extends JFrame{ String text="A JScrollPane manages a viewport, optional vertical and horizontal"+ " scroll bars, and optional row and column heading"+ " viewports. You can find task-oriented documentation of JScrollPane"+ "in How to Use Scroll Panes, a section in The Java Tutorial"; JEditorPane editorPane=new JEditorPane(); JScrollPane scrollPane=new JScrollPane(editorPane); JButton button=new JButton("Wrap"); public LineWrap() { button.addActionListener(new MyActionListener()); Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); scrollPane.setPreferredSize(new Dimension(300, 100)); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorPane.setText(text); contentPane.add(scrollPane); contentPane.add(button); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); } public static void main(String[] args) { new LineWrap(); } class MyActionListener implements ActionListener{ public void actionPerformed(ActionEvent ae) { int wrappedLength=50; // How can I find wrappedLength value???? String wrappedText=WordUtils.wrap(text, wrappedLength); editorPane.setText(wrappedText); } } }
Similar Threads
-
Line wrapping on a JTextPane
By danoc93 in forum AWT / SwingReplies: 7Last Post: 05-20-2012, 07:22 AM -
Turning on/off Word Wrapping in jEditorPane
By Pluto in forum AWT / SwingReplies: 1Last Post: 03-24-2012, 09:33 AM -
how to place cursor at end of each line in JEditorPane
By prasad.vara in forum AWT / SwingReplies: 2Last Post: 10-25-2010, 12:32 PM -
Line Wrapping
By Lil_Aziz1 in forum EclipseReplies: 9Last Post: 06-25-2010, 02:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks