swing之flowlayout
import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; //1.继承 JFrame类 //2.在最上方定义组件 //3.在构造方法中创建组件 //4、在构造方法中添加组件 //5.设置窗体属性 //6.显示窗体 //7.在主函数中创建对象 public class flowlayout1 extends JFrame{ JButton [] a={null,null,null,null,null,null,null,null}; public static void main(String[] args) { // TODO Auto-generated method stub flowlayout1 f1=new flowlayout1(); } public flowlayout1 () { a[0]=new JButton("瓜子"); a[1]=new JButton("话梅"); a[2]=new JButton("西瓜"); a[3]=new JButton("草莓"); a[4]=new JButton("香蕉"); a[5]=new JButton("苹果"); a[6]=new JButton("栗子"); a[7]=new JButton("黄瓜"); //a[8]=new JButton("葡萄"); this.setLayout(new FlowLayout(FlowLayout.LEADING));//默认是边界布局,如果想变成其他布局,加上 this.add(a[0]); this.add(a[1]); this.add(a[2]); this.add(a[3]); this.add(a[4]); this.add(a[5]); this.add(a[6]); this.add(a[7]); this.setTitle("流式布局flowlayout"); this.setSize(400,320); this.setLocation(100, 180); this.setResizable(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步