Put a JButton in the center of the screen with BorderLayout

前端 未结 3 2104
再見小時候
再見小時候 2020-12-04 03:35

How to add a JButton into the center of a JFrame with BorderLayout()? I tried using BorderLayout.CENTER, but instead of the center

3条回答
  •  臣服心动
    2020-12-04 04:31

    Put a JPanel in the CENTER and set the layout to GridBagLayout or BoxLayout as seen in this answer to Set component at center of the page.

    The GridBagLayout is used to center a label containing the yellow/red gradient image seen in the Nested Layout Example.

    Animated image of nested layout example showing size change

提交回复
热议问题