所以目前我的程序只显示 GUI 右下角的一个按钮。但我想在右下角显示两个按钮。任何想法如何将两个按钮设置到右上角?到目前为止,这是我的代码:
import javax.swing.*;
import java.awt.*;
public class Other extends JFrame{
private static final long serialVersionUID = 1L;
public Other() {
super("Buttons");
final Container mainPanel = getContentPane();
mainPanel.setLayout(new BorderLayout());
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BorderLayout());
JPanel inputPanel = new JPanel();
inputPanel.add(new JLabel("RANDOM TEXT HERE"));
inputPanel.add(new JLabel("RANDOM TEXT HERE"));
inputPanel.add(new JLabel("RANDOM TEXT HERE"));
JButton s = new JButton("first");
JButton l = new JButton("second");
buttonPanel.add(s,BorderLayout.LINE_END);
buttonPanel.add(l,BorderLayout.LINE_END); //<-- not working
mainPanel.add(inputPanel,BorderLayout.PAGE_START);
mainPanel.add(buttonPanel,BorderLayout.PAGE_END);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args){
Other o = new Other();
}
}