Java, setting ID for JButton
•
Java
Set the ID for JButton anyway. I'm used to Android
I am looking for the following:
newButton.setId(objectcounter);
Solution
You can use the following attribute names:
newButton.setName(String.valueOf(objectCounter))
Alternatively, you can use clientproperties to store any value:
newButton.putClientProperty("id",Integer.valueOf(objectCounter))
To get a value from a client property map, you need something like this
Object property = newButton.getClientProperty("id"); if (property instanceof Integer) { int objectCounter = ((Integer)property); // do stuff }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码