Java,为JButton设置ID

无论如何都要为JButton设置id.我已经习惯了 Android.

我正在寻找以下内容

newButton.setId(objectcounter);

解决方法

您可以使用以下属性名称
newButton.setName(String.valueOf(objectCounter))

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

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

要从客户端属性映射中获取值,您需要这样的东西.

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

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...