1 回答

TA貢獻1797條經(jīng)驗 獲得超6個贊
使用Node.properties地圖。這允許您使用字符串作為鍵來存儲對象。請確保不要使用類似于static父級屬性的鍵(參考例如AnchorPane.leftAnchor此處),因為這些屬性也存儲在此映射中:
文件
<Button onAction="#handleClicks" text="DECEMBER" textFill="WHITE">
<properties>
<year>
<Integer fx:value="2018"/>
</year>
<month>
<Integer fx:value="12"/>
</month>
</properties>
</Button>
控制器
@FXML
private void handleClicks(ActionEvent event) {
Map<Object, Object> properties = ((Node) event.getSource()).getProperties();
System.out.println("year: "+properties.get("year"));
System.out.println("month: "+properties.get("month"));
}
添加回答
舉報