JLabel-获取父面板? [英] JLabel - get parent panel?

查看:50
本文介绍了JLabel-获取父面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取添加了JLabel的面板的名称?我向不同的JPanels添加了一些JLabel,并且我想根据放置jLabel的面板调用不同的鼠标事件.

Is it possible to get the name of the panel that a JLabel is added to? I added some JLabels to different JPanels, and I want to call different mouse events according to which panel the jLabels are placed upon.

推荐答案

如果运行 label.getParent(),它将返回标签在其中的面板.

If you run label.getParent() it will return the panel the label is inside.

然后您可以调用 parent.getName(),但是事实上您现在拥有的对象可能现在不需要.

You could then call parent.getName() but the fact the you will now have the object you might not need this now.

这篇关于JLabel-获取父面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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