0
import javax.swing.*;
import java.awt.*;
class MyJPanel extends JPanel {
JButton login, register;
public MyJPanel() {
login = new JButton("Login");
register = new JButton("Register");
this.add(register);
this.add(login);
}
}
class MyJFrame extends JFrame {
MyJPanel mjp;
public MyJFrame(String title) {
super(title);
mjp = new MyJPanel();
Container ct = getContentPane();
ct.add(mjp);
setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
setSize(400,400);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class Gui7FirstPage {
public static void main(String[] args) {
MyJFrame mjf = new MyJFrame("Welcome!");
}
}
上記のコードは、2つのボタンのログインと登録をX軸に沿って調整しています。私はBoxLayout.Y_AXISを使ってそれらを積み重ねようとしていますが、動作していないようです。BoxLayout.Y_AXISがスイングで動作しない
2つのボタンが横に並んでいて、それらを真っ直ぐに配置したいと思っています。