[Q#8182473][A#8182674] How to have a Scrollable JTextPane?
https://stackoverflow.com/q/8182473
I would like to have a JTextPane that have scroll bar, how can I do so ? Thanks.
Answer
https://stackoverflow.com/a/8182674
To insert a scroll bar on your new JTextPane, just use a JScrollPane: 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
APIzation
JTextPane txt = new JTextPane();
JScrollPane jsp = new JScrollPane(txt);
package com.stackoverflow.api;
import javax.swing.*;
public class Human8182674 {
public static JScrollPane insertScrollBar(JTextPane txt) {
return new JScrollPane(txt);
}
}
package com.stackoverflow.api;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
/**
* How to have a Scrollable JTextPane?
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/8182674">https://stackoverflow.com/a/8182674</a>
*/
public class APIzator8182674 {
public static JScrollPane haveJtextpane() throws Exception {
JTextPane txt = new JTextPane();
return new JScrollPane(txt);
}
}