Java,为JButton设置ID

前端之家收集整理的这篇文章主要介绍了Java,为JButton设置ID前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
无论如何都要为JButton设置id.我已经习惯了 Android.

我正在寻找以下内容

  1. newButton.setId(objectcounter);

解决方法

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

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

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

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

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

猜你在找的Java相关文章