I have an array of TextAreas. The number of TextAreas is such that not all of them are visible. I would like to add a scroll bar so I can scroll all of them into view. I've tried various ways but none worked.
The following is a code stub that produces the textareas but doesn't show a scrollbar. Appreciate any help. Thanks.
Always use a proper layout manager. With that, all you need to do is wrap your widget inside a JScrollPane and add the scroll pane to the parent panel.
yes, this is one of the constructors from JPanel's apidocs
public JPanel(LayoutManager layout)Create a new buffered JPanel with the specified layout manager
layout - the LayoutManager to use
to follow up on Maneesh's comment re null layouts, the reason there was no scrollbar would be due to
you setting the scrollpane's layout to null (a null layout makes you responsible for just about everything).
The JScrollBar is a separate component, but when added to a null layout it needs to have a location and a size,
otherwise defaults to 0,0,0,0.
The reason I didn't use a Layout Manager was because I wanted the user to be able to resize the individual text areas. I also wanted to write some code so that columns and rows of text areas could also be moved - similar to a spreadsheet.
A GridLayout would work very nicely except column and row movement would be impossible - I think.
I've been putting off working with that GridBag thingy, it looks a bit intimidating and I'm not sure it would allow me to do what I want to do anyway.
Everything works fine if the buttons are coded individually. However, if I try using a button array (btn) and enter them via a for loop I get a runtime error.
Exception in thread "main" java.lang.IllegalArgumentException: Component must be
The code is as follows:
Appreciate any help.
Ted Newholm wrote:I've fixed up the initializing problem but I'm still getting a whole pile of runtime errors... Am I doing something wrong with the GroupLayout?
If you're getting runtime errors, then yes, by definition you're doing something wrong. And the error messages are supposed to convey information, you know. I suggest you have a look at them and find out what that information is. That's what I would do. Without that information you're basically guessing in the dark.