简体   繁体   English

Java GUI JScrollPane隐藏文本

[英]Java GUI JScrollPane hiding text

Currently I am trying to get a JScrollPane to work with a GUI I am creating. 目前,我正在尝试使JScrollPane与正在创建的GUI一起使用。 I currently have a textarea called consoleTextArea and I want to be able to scroll through it. 我目前有一个名为consoleTextArea的文本区域,我希望能够滚动它。 Currently my code is: 目前,我的代码是:

consoleTextArea = new JTextArea();
consoleTextArea.setBounds(10, 11, 546, 459);

JScrollPane scroller = new JScrollPane(consoleTextArea);
scroller.setBounds(0, 451, 551, -451);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel.add(scroller);

If I use panel.add(scroller) , I don't even see the textArea. 如果我使用panel.add(scroller) ,我什至看不到textArea。
If I use panel.add(consoleTextArea) , I see the text area but it cannot scroll. 如果使用panel.add(consoleTextArea) ,我会看到文本区域,但无法滚动。

What am I doing wrong here? 我在这里做错了什么?

More than likely, you're not using a layout manager. 您很有可能没有使用布局管理器。 Without using a layout manager ( absolute positioning ) you encounter you encounter these types of problems where components are not sized or positioned correctly. 如果不使用布局管理器( 绝对定位 ),则会遇到这些类型的问题,其中组件的大小或放置不正确。 A good reason, therefore to use one. 因此,使用一个很好的理由。

Read: Using Layout Managers 阅读: 使用布局管理器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM