热门

最新

红包

立Flag

投票

同城

我的

发布
jackchuanqi
传奇开心果编程
2 年前
truejackchuanqi

setLayout(new GridLayout(3, 2));

add(new JButton("Button 1"));

add(new JButton("Button 2"));

add(new JButton("Button 3"));

add(new JButton("Button 4"));

add(new JButton("Button 5"));

add(new JButton("Button 6"));

}



public static void main(String[] args) {

SwingUtilities.invokeLater(() -> {

GridLayoutExample example = new GridLayoutExample();

example.setVisible(true);

});

}

}

```
5. BoxLayout:箱式布局,按照指定的方向(水平或垂直)排列组件。

```java

import javax.swing.*;

import java.awt.*;


public class BoxLayoutExample extends JFrame {

public BoxLayoutExample() {

setTitle("BoxLayout Example");

setSize(300, 200);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

add(new JButton("Button 1"));

add(new JButton("Button 2"));

add(new JButton("Button 3"));

}


public static void main(String[] args) {

SwingUtilities.invokeLater(() -> {

BoxLayoutExample example = new BoxLayoutExample();

example.setVisible(true);

});

}

}

```

每日学习打卡
青岛市城阳区
CSDN App 扫码分享
分享
1
2
打赏
  • 复制链接
  • 举报
下一条:
HarmonyOS应用开发者高级认证
立即登录