Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a Scrollable JTextPane?

I would like to have a JTextPane that have scroll bar, how can I do so ? Thanks.

like image 948
DNB5brims Avatar asked Nov 18 '11 12:11

DNB5brims


People also ask

How do I add a scroll pane to textArea?

The Easiest way to implement scrollbar using java swing is as below : Navigate to Design view. right click on textArea. Select surround with JScrollPane.

How do I add a scrollbar to a photo?

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.


1 Answers

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

like image 183
Alberto Solano Avatar answered Oct 11 '22 10:10

Alberto Solano