Adding an horizontal scroll

+1 Cem Saglam · August 7, 2014

I have a program in which the user can add buttons on a panel. But when there are a lot of buttons, naturally we no longer can see all of the buttons. For this, I want to insert an horizontal scroll bar, so that all the buttons can be seen by sliding.

I have read and tried many "solutions" on the usage of JScrollBar, but so far nothing helped.

Can anyone help me with this? Thanks.

Post a Reply


Oldest  Newest  Rating
0 Cem Saglam · August 9, 2014
It didn't help :l
A bar (or something else) didn't even show up in the GUI. (I did add it to the frame)
Whenever a button is added, the frame gets packed. Can the problem be related to this?
0 Colin James · August 8, 2014
Don't use a JScrollBar. Use a JScrollPane:
JPanel panel = new JPanel();
// assuming class extends JFrame
JScrollPane sp = new JScrollPane(panel);

That should work for you.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator