如何为Jlabel提供布局管理器? [英] How Do I Give Jlabel A Layout Manager?
本文介绍了如何为Jlabel提供布局管理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为Jlable容器提供布局管理器?我尝试这样设置:
How do i give a Jlable container a layout manager? I tried to set it this way :
lab1=new JLabel(new GridLayout(1,1,15,15));
但它说这个构造函数是未定义的。任何人都可以帮我这个吗?
But it says this constructor is undefined. Can anyone help me with this?
推荐答案
下面的代码片段创建了GridLayout对象及其管理的组件。
GridLayout experimentLayout = new GridLayout(0,2);
...
compsToExperiment.setLayout(experimentLayout);
compsToExperiment.add(新JButton(按钮1));
compsToExperiment.add(新JButton(按钮2));
compsToExperiment.add(新JButton(按钮3));
compsToExperiment.add (新JButton(长命名按钮4));
compsToExperiment.add(新JButton(5));
或
GridLayout experimentLayout = new GridLayout(0,2);
compsToExperiment.setLayout(experimentLayout);
lab1 = new JLabel(MyLabel);
compsToExperiment.add(lab1);
The code snippet below creates the GridLayout object and the components it manages.
GridLayout experimentLayout = new GridLayout(0,2);
...
compsToExperiment.setLayout(experimentLayout);
compsToExperiment.add(new JButton("Button 1"));
compsToExperiment.add(new JButton("Button 2"));
compsToExperiment.add(new JButton("Button 3"));
compsToExperiment.add(new JButton("Long-Named Button 4"));
compsToExperiment.add(new JButton("5"));
or
GridLayout experimentLayout = new GridLayout(0,2);
compsToExperiment.setLayout(experimentLayout);
lab1=new JLabel("MyLabel");
compsToExperiment.add(lab1);
这篇关于如何为Jlabel提供布局管理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文