JPanel中组件的更改问题?

xietangz 2002-03-11 01:43:34
程序如下

...

JPanel panelleft = null;
JPanel panelright = null;
JLable labelleft = null;
JLabel labelright_top = null;
JLabel labelright_center = null;

JSplitPane sp = null;
public test()
{
Container content = getContentPanel();
panelright = new JPanel();
labelright_top = new JLabel("this is right panel top");
labelright_center = new JLabel("this is right panel center");
panelright.setLayout(new BorderLayout());
panelright.add(labelright_top,BorderLayout.NORTH);
panelright.add(lableright_center,BorderLayout.CENTER);

panelleft = new JPanel();
labelledt = new JLabel("this is panel left");
panelleft.add(labelleft);

sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
sp.add(panelleft,JSplitPane.LEFT);
sp.add(panelRight,JSplitPane.RIGHT);
sp.setOneTouchExpandable(true);
sp.setDividerSize(10);
sp.setDividerLocation(120);
content.add(sp);
}

....


现有一按钮单击后将更改panelright中 BorLayout.CENTER中的组件:

...
JPanel panelright = null;
public button(JPanel panelright)
{
this.panelright = panelright;


public class buttonListerer implements ActionListener
{
public void actionPerforred(ActionEvent e)
{
//panelright.removeAll();
panelright.add(new JButton("this is panelright center"),BorderLayout.CENTER);


}

}
...

上面如何remove panelright中已存在BorderLayout.CENTER位置上的labelright_center
而增加为 new JButton("this is panelright center");


}

...全文
8 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复

还没有回复,快来抢沙发~

发帖
非技术区
创建于2007-09-28

2.3w+

社区成员

Java 非技术区
申请成为版主
帖子事件
创建了帖子
2002-03-11 01:43
社区公告
暂无公告