gpt4 book ai didi

java - 在 JTabbedPane 中向 JTextPane 添加滚动条?

转载 作者:行者123 更新时间:2023-11-30 07:32:43 25 4
gpt4 key购买 nike

我将 JTextPanes 添加到 JTabbedPane。

如何让 JTextPanes 具有垂直滚动条?

我已经尝试将 JTextPane 包装在 JScrollPane 中并将 JScrollPane 添加到 JTabbedPane 但没有显示任何文本。

最佳答案

我让它工作了,下面的代码产生了这个截图:

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);
}

}

关于java - 在 JTabbedPane 中向 JTextPane 添加滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6387409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com