Topic: Panel问题

  Print this page

1.Panel问题 Copy to clipboard
Posted by: API
Posted on: 2004-10-27 22:08

我做了1个继承框架(Frame)类的JAVA程序,窗体中间放了一个Panel对象,然后在Panel上加了N个按钮,但是执行程序后,只看到Panel,而按钮并没有在Panel上显示出来,当我拖动窗口边缘改变了窗口大小后,按钮才显示出来。不知道怎么才能让按钮一开始就能显示出来呢?应该怎样改呢?

(我不太会表达,不知道说清了吗。。。?)

2.Re:Panel问题 [Re: API] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-28 08:38

虽然你大致说清楚了,不过还是建议你贴出全部或部分代码,便于大家分析。

3.Re:Panel问题 [Re: API] Copy to clipboard
Posted by: zgxsj
Posted on: 2004-10-28 16:13

应该是缺少以下代码:
Panel.setPreferredSize(new Dimension(W,H));
Panel.setMinimumSize(new Dimension(W,H));
是因为按钮的宽高超过 Panel 的宽高,这样,Panel的宽高就变为默认最小值,所以,你就看不到按钮了,把默认最小值改过来就好了

4.Re:Panel问题 [Re: API] Copy to clipboard
Posted by: API
Posted on: 2004-10-28 20:12

代码如下,大家帮我看一下,谢谢了~~

import java.awt.*;
import java.awt.event.*;
public class abc {
public static void main(String[] args) {
MyForm w = new MyForm("abc");
}
}

class MyForm extends Frame {
public MyForm(String s) {
super ( s );
setLayout(null); //采用空布局
addWindowListener(new WindowAdapter() { //退出
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
this.setBounds(300, 200, 260, 260); //设置宽高
setVisible(true); //设置可见

int n = 5;
Button[] button = new Button[n * n];
Panel panel = new Panel();
panel.setLayout(new GridLayout(n, n));
panel.setBounds(10, 50, 150, 150);
add(panel);

for (int i = 0; i < button.length; i++) {
button[i] = new Button(""+i);
panel.add(button[i]);
}
}
}

5.Re:Panel问题 [Re: API] Copy to clipboard
Posted by: zhongjinao
Posted on: 2004-11-02 17:54

setVisible(true); //设置可见

将这一句放在后面就可以了。

6.Re:Panel问题 [Re: API] Copy to clipboard
Posted by: xiaobing
Posted on: 2004-11-04 23:42

setVisible(true);

请看完贴再回答,不然有水贴的嫌疑!

7.Re:Panel问题 [Re: API] Copy to clipboard
Posted by: xericfish
Posted on: 2004-11-11 15:56

在main函数里加上 w.setVisible(true);


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923