1. import java.awt.Button;

  2. import java.awt.Panel;

  3.  

  4. import javax.swing.BoxLayout;

  5. import javax.swing.JFrame;

  6.  

  7. public class HBox extends JFrame {

  8.  

  9.   public HBox() {

  10.     super("Horizontal Box Test Frame");

  11.     setSize(200, 100);

  12.     Panel box = new Panel();

  13.  

  14.     // Use BoxLayout.Y_AXIS below if you want a vertical box

  15.     box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));

  16.     setContentPane(box);

  17.     for (int i = 0; i < 3; i++) {

  18.       Button b = new Button("B" + i);

  19.       box.add(b);

  20.     }

  21.     setDefaultCloseOperation(EXIT_ON_CLOSE);

  22.     setVisible(true);

  23.   }

  24.  

  25.   public static void main(String args[]) {

  26.     HBox bt = new HBox();

  27.   }

  28. }


转载于:https://my.oschina.net/wwwfanganwangcom/blog/219786

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐