I want to add many buttons on a panel with gridlayout, When the count of buttons reach some number, I hope that a JScrollPane can appear. I have tried, but no result ! please help me !
the scrollbars will appear when the preferred size of the scrollpane is less than that of it's content.
so, if the scrollpane is added directly to the frame/contentPane, its preferred size will be determined by the size of the frame/contentPane.
if the scrollpane is added to a panel, and the panel added to the frame/contentPane, you will need to set a preferred size for the scrollPane scrollPane.setPreferredSize(new Dimension(100,100));