GridLayout 中控件的删除

OK102030 OK102030 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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;
}
...全文
评论 2
收藏 已收藏
分享
返回顶部
OK102030
Java SE 62,620 成员 307,251 内容