Java, set id for JButton

Is there any way to set id for JButton. I'm used to it on Android.

I am looking for something like the following:

newButton.setId(objectcounter);
+5
source share
1 answer

There is a property name that you can use:

newButton.setName(String.valueOf(objectCounter))

you can also use clientProperties, which allows you to store arbitrary values:

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

To get the value from the client property map, you need something like this.

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

All Articles