从JPanel完全删除JLabel ...未设置Visible(False) [英] Fully REMOVE JLabel from JPanel...not setVisible(False)

查看:81
本文介绍了从JPanel完全删除JLabel ...未设置Visible(False)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的问题.我在JFrame上有一个JPanel.我在JPanel上有一个JLabel.我想知道如何在运行时从JPanel中完全删除JLabel?

I have a fairly simple question. I have a JPanel on a JFrame. I have a JLabel on the JPanel. How, I wonder, do i FULLY REMOVE the JLabel from the JPanel during runtime?

ImageIcon image7= new ImageIcon("archmageanim.gif");
JLabel label7 = new JLabel("", image7, JLabel.CENTER);
p.add( label7, "0 , 6" ); //This coordinate has to do with a layout manager I'm using - it 
                          //I'm using - it works fine.

我一直在寻找这种解决方案...但是每个人都说最简单的方法"是设置setVisible(false)...但这并不能真正删除对象-_-.如何删除?

I have looked for this solution...but everyone says "the easiest way" is to set setVisible(false)...but that doesn't truly remove the object -_-. How can I REMOVE it?

推荐答案

难道不能仅使用它来查找JLabel的父容器,然后使用remove方法?

Can't you just use this to find the parent Container of the JLabel and then use the remove method?

Container parent = label7.getParent();
parent.remove(label7);
parent.validate();
parent.repaint();

那应该完全删除标签,然后刷新父容器.

That should remove the label altogether and then refresh the parent Container.

这篇关于从JPanel完全删除JLabel ...未设置Visible(False)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆