package HeadFirstJava;
import javax.swing.*;
import java.awt.*;
public class Panel1 {
public static void main(String[] args) {
Panel1 gui = new Panel1();
gui.go();
}
public void go() {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setBackground(Color.darkGray);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
// panel's default layout manager is 'flow layout'
// but we change it to 'box layout'
JButton button = new JButton("shock me");
JButton buttonTwo = new JButton("bliss");
panel.add(button);
panel.add(buttonTwo);
frame.getContentPane().add(BorderLayout.EAST, panel);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
box layout DEMO
最新推荐文章于 2022-09-12 03:45:31 发布