当前位置: 技术问答>java相关
小问题求救~~~
来源: 互联网 发布时间:2015-02-21
本文导语: 关于panel定位的! Panel hostPanel = new Panel(); hostPanel.setLayout(new GridLayout(2, 1)); hostPanel.add(new Label("Host")); hostPanel.add(new Label("IP")); 这应该是定义两行一列布局吧! 而我把G...
关于panel定位的!
Panel hostPanel = new Panel();
hostPanel.setLayout(new GridLayout(2, 1));
hostPanel.add(new Label("Host"));
hostPanel.add(new Label("IP"));
这应该是定义两行一列布局吧!
而我把GridLayout(2,1)改为3,2 那一共可以摆放6个元素!
可测试时只显示前两 个! 为什么?
代码如下:
Panel hostPanel = new Panel();
hostPanel.setLayout(new GridLayout(3, 2));
hostPanel.add(new Label("Host"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
add(hostPanel);
请各位指点!
Panel hostPanel = new Panel();
hostPanel.setLayout(new GridLayout(2, 1));
hostPanel.add(new Label("Host"));
hostPanel.add(new Label("IP"));
这应该是定义两行一列布局吧!
而我把GridLayout(2,1)改为3,2 那一共可以摆放6个元素!
可测试时只显示前两 个! 为什么?
代码如下:
Panel hostPanel = new Panel();
hostPanel.setLayout(new GridLayout(3, 2));
hostPanel.add(new Label("Host"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
add(hostPanel);
请各位指点!
|
没问题!是6个。
import java.awt.*;
public class MyFrame extends Frame{
public static void main(String[] args){
MyFrame f = new MyFrame();
f.sh();
}
public void sh(){
Panel hostPanel = new Panel();
hostPanel.setLayout(new GridLayout(3, 2));
hostPanel.add(new Label("Host"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
add(hostPanel);
setSize(200,200);
show();
}
}
import java.awt.*;
public class MyFrame extends Frame{
public static void main(String[] args){
MyFrame f = new MyFrame();
f.sh();
}
public void sh(){
Panel hostPanel = new Panel();
hostPanel.setLayout(new GridLayout(3, 2));
hostPanel.add(new Label("Host"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
hostPanel.add(new Label("IP"));
add(hostPanel);
setSize(200,200);
show();
}
}
|
保存,重新编译
|
Maybe you should adjust the size for showing it to be enough large.
|
把panel的大小设置一下