Java秋千:将滚动条添加到Textarea
我有一个文本区域,可以更新按钮按下(此更新正常)。当它更新时,在需要滚动条的文本区域中会出现一个长列表。但是,当我在下面添加最后两行时,不仅不会出现滚动条,而且文本也不会出现。我该如何解决? (我是Java Swing的新手,所以答案越简单越好)
textArea1 = new JTextArea("");
textArea1.setBounds(450, 40, 400, 700);
frame.getContentPane().add(textArea1);
JScrollPane scroll = new JScrollPane(textArea1);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
I have a text area that updates a button press (this updating works fine). When it updates, a long list appears in the text area that requires a scroll bar. However, when I add the last two lines below, not only does the scroll bar not appear, text doesn't appear as well. How do I fix this? (I'm new to java swing so the simpler the answer the better)
textArea1 = new JTextArea("");
textArea1.setBounds(450, 40, 400, 700);
frame.getContentPane().add(textArea1);
JScrollPane scroll = new JScrollPane(textArea1);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将
jscrollpane
添加到jframe
。Oracle有一个有用的教程,创建带有swing 的GUI。使用Netbeans IDE部分跳过学习秋千。
您应该使用摇摆布局管理器,而不是
setBounds
。You add the
JScrollPane
to theJFrame
.Oracle has a helpful tutorial, Creating a GUI With Swing. Skip the Learning Swing with the NetBeans IDE section.
You should be using Swing layout managers, rather than
setBounds
.