9

とにかくのIDを設定することはありますかJButton。私はAndroidでそれに慣れています。

私は次のようなものを探しています:

newButton.setId(objectcounter);
4

1 に答える 1

16

使用できるプロパティ名があります。

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
}
于 2012-04-09T07:29:36.110 に答える