I am using JScrollpane and adding buttons on it dynamically. JScrollpane does not allow use of layouts. I want to increase space vertically and horizontally between buttons.
Asked
Active
Viewed 68 times
1
-
2Create a [mcve]. – George Z. Nov 11 '21 at 07:38
-
1Insert a panel in between the scrollpane and the buttons, i.e. add the buttons to the panel and the panel to the scrollpane. – Thomas Nov 11 '21 at 07:42
-
Create a panel, add you components to this panel, using what ever layout you want. Set this panel as the scroll panels `viewport view` – MadProgrammer Nov 11 '21 at 07:48
-
For [example](https://stackoverflow.com/questions/24987832/jscrollpane-for-a-jpanel-inside-a-jpanel/24987880#24987880) – MadProgrammer Nov 11 '21 at 08:05
-
_adding buttons on it dynamically_ how do you add multiple buttons to the JScrollpane ? – c0der Nov 11 '21 at 08:19
-
1@Thomas Thanks. It is easy and useful method. – Yogiraj Nov 11 '21 at 08:28
1 Answers
1
Add JPanel
to your JScrollPane
, and change the layout of the JPanel
.
After that, you can build all your gui inside your JPanel
without the limitation of JScrollPane
.

Programmer
- 803
- 1
- 6
- 13