This problem looks trivial, but I can’t find the solution.
When I create a form it contains a JTextArea. I want to put large constant text in it. If the text is say 1000 lines long, I want my JTextArea to be 1000 lines high (to be large enough to display the entire text without scrollbars). JTextArea is inside a panel which can have scrollbar so it is not a problem when it gets too large (there are two JTextArea in that panel.. something like in a diff tool). Does anybody knows how can I achieve this? Thanks.
The
BorderLayoutwill handle the scrollbar out of the box if you simply put yourJTextAreain aJScrollPanebefore you add it to yourJPanel.FlowLayout, on the other hand, does not. It will not display the scroll bar unless, as @Xorty intimates, you callsetPreferedSize()on yourJScrollPaneand give it the dimension that you would like.