Java,为JButton设置ID [英] Java, set ID for JButton

查看:68
本文介绍了Java,为JButton设置ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,都可以为JButton设置ID.我已经习惯了Android.

Is there anyway to set an id for a JButton. I'm used to it in Android.

我正在寻找类似以下内容的东西:

I'm looking for something like the following:

newButton.setId(objectcounter);

推荐答案

有一个可以使用的属性名称:

There is a property name which you could use:

newButton.setName(String.valueOf(objectCounter))

或者,您可以使用clientProperties,它可以存储任意值:

alternatively, you could use clientProperties which lets you store arbitrary values:

newButton.putClientProperty("id", Integer.valueOf(objectCounter))

要从客户端属性映射中获取值,您将需要以下内容.

To fetch the value from the client property map you'll need something like this.

Object property = newButton.getClientProperty("id");
if (property instanceof Integer) {
   int objectCounter = ((Integer)property);
   // do stuff
}

这篇关于Java,为JButton设置ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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