Put a JButton in the center of the screen with BorderLayout

前端 未结 3 2092
再見小時候
再見小時候 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:34

    try this

    frame.getContentPane().setLayout(new BorderLayout(0, 0));
    
    JButton btnNewButton = new JButton("New button");
    frame.getContentPane().add(btnNewButton, BorderLayout.CENTER);
    

提交回复
热议问题