I would like to have a JTextPane that have scroll bar, how can I do so ? Thanks.
The Easiest way to implement scrollbar using java swing is as below : Navigate to Design view. right click on textArea. Select surround with JScrollPane.
Setting ScrollBar to an imageCreate a pane to hold the image view such as scroll pane, vBox, etc.. Add a listener to the value property, of the scroll bar. Based on the orientation of the scroll bar, set the X/Y layouts of the layout pane, with the negative of the new value of the scroll bar.
To insert a scroll bar on your new JTextPane, just use a JScrollPane:
JTextPane txt = new JTextPane();
JScrollPane jsp = new JScrollPane(txt);
JTextPane API: http://download.oracle.com/javase/6/docs/api/javax/swing/JTextPane.html
JScrollPane API: http://download.oracle.com/javase/6/docs/api/javax/swing/JScrollPane.html
If you have some issues, take a look at this SO question : Java JTextPane JScrollPane Display Issue
Or take a look at: http://www.daniweb.com/software-development/java/threads/30283
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With