Java-GridLayout是否可以在同一侧具有两个组件? [英] Java - Is it possible to have two components on the same side with GridLayout?

查看:236
本文介绍了Java-GridLayout是否可以在同一侧具有两个组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用GridLayout在创建注释"按钮下具有保存注释"按钮?如果没有,我应该使用哪种布局? dataPanel包含文本字段和标签. buttonPanel是保存笔记按钮,namePanel是创建笔记按钮.

Is it possible to have the "Save note" button under the "Create note" button using GridLayout? If not, what layout should I be using? dataPanel contains both text fields and both labels. buttonPanel is the save note button and namePanel is the create note button.

    container.add(dataPanel, BorderLayout.CENTER);
    container.add(buttonPanel, BorderLayout.SOUTH);
    container.add(namePanel, BorderLayout.EAST);

提前谢谢!

推荐答案

当然可以!只需定义一个具有2行3列的网格布局即可: -第一栏将包含标签 -第二栏将包含文本框 -第三列将包含按钮

Of course it is possible! Simply define a grid layout with 2 rows and 3 columns each: - first column will contain the labels - second column will contain the text boxes - 3rd column will contain the buttons

此外,为什么在添加到GridLayout时使用BorderLayout常量?使用GridLayout确定行/列后,只需按从左到右,从上到下在网格"中排列的顺序添加即可.因此,在上面的示例中,您将执行以下操作:

Also, why are you using the BorderLayout constants when adding to the GridLayout? With GridLayout once you have decided on the rows/columns simply add them in the order you want them to be layed out in the "grid" from left to right, top to bottom. So in the above example you will do something like this:

JPanel p = new JPanel( new GridLayout(2,3) );
p.add( /* enter the desired note label */ );
p.add( /* note name here text box */ );
p.add( /* create note button */ );
p.add( /* enter a new note label */ );
p.add( /* note text here text box */ );
p.add( /* save note button */ );

这篇关于Java-GridLayout是否可以在同一侧具有两个组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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