I have JTextPanes which are added to a JTabbedPane.
How do I get the JTextPanes to have vertical scrollbars?
I've tried wrapping the JTextPane inside a JScrollPane and adding the JScrollPane to the JTabbedPane but none of the text shows.
I get it to work, the code below produces this screenshot:
public class Test {
public static void main(String[] args) throws BadLocationException {
JFrame frame = new JFrame("Test");
JTabbedPane tabs = new JTabbedPane();
JTextPane textPane = new JTextPane();
textPane.getDocument().insertString(0, "Hello World!", null);
tabs.addTab("Test", new JScrollPane(textPane));
frame.add(tabs);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setVisible(true);
}
}
Try adding the JTextPane onto a JScrollPane and then add the JScrollPane to the panel/tabbedpane.
See this code sample:
JTextPane txtpn = new JTextPane();
JScrollPane scrl = new JScrollPane(txtpn);
myTabPane.add(scrl); //Or whatever you call that pane
I haven't tested this, but it works perfect with other JComponents on JPanels
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.