Adding an horizontal scroll

+1 Cem Saglam · August 7, 2014
Hello,

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

Replies

Oldest  Newest  Rating
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);
add(sp);


That should work for you.
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?
  • 1

Java / Android Development

107,109 followers
About

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

Links
Moderators
Bucky Roberts Administrator