2014-03-03 53 views
1

我不明白为什么这不起作用......它隐藏了JTextArea。JScrollPane隐藏文本区域

JTextArea _area=new JTextArea(); 
_area.setBounds(10, 10, 465, 250); 
add(_area); 

JScrollPane scroller=new JScrollPane(_area); 
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 
add(scroller); 

回答

2

编辑:

洗牌界值设定的范围只ScrollPane而不是TextArea

 JTextArea _area = new JTextArea(); 
//  _area.setBounds(10, 10, 400, 250); 
     add(_area); 

     JScrollPane scroller = new JScrollPane(_area); 
     scroller.setBounds(10, 10, 400, 250); 
     scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 
     add(scroller); 
+0

因为我在组件上使用setBounds(),所以我在框架上设置了setLayout(null)。 – Luka

+0

我编辑了答案。 – Prasad

+0

非常感谢你,我不知道。它帮助了! :) – Luka