GridLayout 中控件的删除

OK102030 2005-02-02 09:52:24
GridLayout 中控件的删除

// GridLayoutDemo

import java.awt.*;

class GridLayoutDemo extends Frame
{
public GridLayoutDemo(String title)
{
super(title);
GridLayout gridLayout = new GridLayout(2, 3);

setLayout(gridLayout); // 设置这个容器的布局管理器。
gridLayout.setRows(3);
// gridLayout.setRows(2); // 不足自动添加
gridLayout.setColumns(4); // 设了4列, 实际只用到3列

String str[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
buttonAry = new Button[str.length];
for(int i = 0; i < str.length; i ++)
{
buttonAry[i] = new Button(str[i]);
add(buttonAry[i]);
}

gridLayout.removeLayoutComponent(buttonAry[0]); // Button 1 并没被删除, 为什么?
// 从这个边界布局中删除指定的组件。
//buttonAry[0].setLabel("well");
//gridLayout.addLayoutComponent("btn", buttonAry[0]);
//btn.setLabel("well");
}

public static void main(String[] args)
{
GridLayoutDemo t = new GridLayoutDemo("list demo");
t.setSize(400, 300);
t.setVisible(true);
}

private Button[] buttonAry;
}
...全文
517 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
JacksonRuan 2005-02-02
  • 打赏
  • 举报
回复
我也顶一下!
OK102030 2005-02-02
  • 打赏
  • 举报
回复
自己帮自己顶一下

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧