放置JscrollBar后未显示swing Java JTextArea
我是Jframes的新手,我想设计一个带有文本框和两个按钮的窗口。除了滚动条部分,我可以让它工作。 我已经编写了下面的代码来启用文本区域的滚动条
private JTextArea outputPane;
outputPane = new JTextArea();
outputPane.setColumns(20);
outputPane.setRows(5);
outputPane.setFont(new Font("Monospaced", Font.PLAIN, 18));
outputPane.setBounds(12, 13, 408, 189);
contentPane.add(outputPane);
JScrollPane scrollPane = new JScrollPane(outputPane);
jScrollPane1.setBounds(399, 13, 21, 189);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
现在的问题是,我在窗口上得到一个禁用的滚动条,但我看不到我的文本区域
请帮我解决这个问题。我甚至尝试过使用WindowsBuilder,但我想不出来
详细的解释与更正的代码将不胜感激,因为我仍然在学习阶段
提前谢谢
# 1 楼答案
首先看一下Laying Out Components Within a Container和How to Use Scroll Panes和How to Use Text Areas可能不会有什么害处
可能的问题是,您看到的是
JTextArea
,“禁用”滚动条只是因为您使用的是scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
,它将始终显示滚动条,即使没有什么可滚动的,所以它可能看起来是空的