Scrollbars not appearing in JScrollPane

后端 未结 2 1249
旧巷少年郎
旧巷少年郎 2021-01-05 21:23

I want to make a window with two buttons with great heights and a scrollbar on a side. The problem is that no scrollbar appears. Here is my code

public class         


        
2条回答
  •  长情又很酷
    2021-01-05 21:29

    Scrollbars appear when the preferred size of the component added to the scollpane is greater than the size of the scrollpane.

    It is the job of the layout manager to determine the preferred size of the panel. It is also the job of the layout manager to determine the size and location of the components added to the panel.

    Get rid of the null layout and use a layout manager and scrollbars will appear when required automatically.

    If you want components to be displayed differently from a vertical point of view, then you need to use a different layout manager. Maybe you can use a BoxLayout with a verticxal layout. You can use:

    panel.add( Box.createVerticalStrut(400) );
    

    to add vertical space between the two components.

提交回复
热议问题