简体   繁体   English

JTextArea始终显示垂直滚动条,为什么?

[英]Vertical scrollbar always appears for JTextArea, why?

new JScrollPane(originalText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)

I clearly write "as needed," but the scrollbar appears anyway in the blank JTextArea. 我清楚地写“按需”,但滚动条无论如何都出现在空白的JTextArea中。 Why? 为什么? How can I prevent this? 我怎么能阻止这个?

The code you have given is wrong. 您提供的代码是错误的。 Jscrollpane doesn't have a constructor like you have mentioned. Jscrollpane没有像你提到的构造函数。 I think it should be JTextArea instead. 我认为它应该是JTextArea。

And the answer for your question lies in your parent layout. 你的问题的答案在于你的父布局。 Please post your layout structure. 请发布您的布局结构。 In general, trying to change your parent's layout to FlowLayout/BorderLayout should show you different results. 通常,尝试将父级布局更改为FlowLayout / BorderLayout应该会显示不同的结果。

It could be if you specified rows argument in the JTextArea constructor. 可能是您在JTextArea构造函数中指定了rows参数。 So the area preferred height is bigger than JScrollPane's height and the vertical scroll is needed. 因此区域首选高度大于JScrollPane的高度,需要垂直滚动。

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

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