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");


}

...全文
35 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

23,405

社区成员

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

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