小编AHi*_*ani的帖子

如何在网格布局中设置按钮的位置?

我的代码:

public class Form {
    public static void main(String[] args) {
        Form form = new Form();
        form.go();
    }

    public void go() {
        JFrame form = new JFrame();
        GridLayout layout = new GridLayout(2,7);
        Label nameLabel = new Label("Name");
        form.setLayout(layout);
        JTextField nameBox = new JTextField();
        form.getContentPane().add(nameLabel);
        form.getContentPane().add(nameBox);
        form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        form.setSize(500,500);
        form.setVisible(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,我如何设置JTextField的这个位置,使其为2,7而不是1,2?

java swing grid-layout

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

grid-layout ×1

java ×1

swing ×1