Question

I am creating a GUI with Netbeans that uses JTextAreas to display text content. The content of the JTextAreas may sometimes be long enough to justify scrollbars, but this will not always be the case. Netbeans automatically puts JTextAreas into JScrollPanes for this very issue.

However, my JTextAreas are 40 pixels in height. As the preferredScrollableViewportSize is [194, 94], a scrollbar shows up no matter how long the text in the JTextArea is. I have set the preferredSizes for the JTextArea and the JScrollPane containing it to a height of 35 pixels, but this has done nothing.

The preferredScrollableViewportSize field in the JTextArea properties is greyed out and I can't change it. From code, I can get

jTextArea1.getPrefferedScrollableViewportSize()

but there is no equivalent set method. I have tried

jScrollPane1.getViewport().setPreferredSize(new Dimension(10, 10));

but this effects no change.

Does anyone know a way to remove the scrollbars except when they are needed?

Was it helpful?

Solution

Set the columns and rows property

See:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top