如何设置按钮在网格布局中的位置? [英] How do you set the position of button in grid layout?

查看:190
本文介绍了如何设置按钮在网格布局中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码:

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);
    }
}

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

Now, how can I set this position of the JTextField so its 2,7 and not 1,2?

推荐答案

尝试将空组件添加到2,7之前的位置,例如:

Try adding empty components into the positions before 2,7 , something like:

form.add(nameLabel);
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(new JPanel());
form.add(nameBox);

这篇关于如何设置按钮在网格布局中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆