Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to make a JPanel with a GridLayout scroll

843807Mar 11 2004 — edited Mar 12 2004
I am using a JPanel to hold around 100 buttons. The JPanel is using GridLayout to organise these buttons in rows of 3 buttons per row. i.e.
buttonPanel.setLayout(new GridLayout(33,3));
As there are so many buttons they obviously don't all fit in the viewable area of the screen. To get around this I am trying to use a JScrollPane on the buttonPanel to make it scroll but I can't get it to work. I have tried both creating a seperate JScrollPane object and adding the buttonPanel to it
 
JScrollPane buttonScroll = new JScrollPane();

buttonPanel.setLayout(new GridLayout(33,3));
buttonPanel.setPreferredSize(new Dimension(380,400));
buttonPanel.setMaximumSize(new Dimension(380,400));
buttonScroll.add(buttonPanel);
and also embeding everything into a new JPanel like:
buttonHolder.add(new JScrollPane(buttonPanel),BorderLayout.CENTER);
Neither way works. Any ideas. I've read about view port but not exactly sure what this is or if this will fix my problem.

Help urgently required.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2004
Added on Mar 11 2004
7 comments
1,262 views