我有一个包含一些标签、文本字段和按钮的 Anchorpane。单击按钮时会打开一个新窗口。从新窗口中选择名称和 ID 后,按键盘窗口中的 Enter 按钮会关闭并且 name 和 id 被传递到已经打开的 Anchorpane。我必须在Anchorpane的标签上设置名称和ID。我正在获取值,但在不刷新 anchor 面板的情况下,它不会在标签中设置。
如何在不按任何按钮加载 anchor 面板的情况下再次刷新 anchor 面板。我看到了类似的问题,但对我来说没有任何作用。
我传递的数据如下;
FXMLLoader load = new FXMLLoader();
try {
Pane root = load.load(getClass().getResource(FXML_CTRL_BILL).openStream());
Item_bill bill = load.getController();
bill.setDataCustomer(name, id);
} catch (IOException e) {
e.printStackTrace();
}
我在 Item_bill Controller 中获得了传递的值,如下所示
public void setDataCustomer(String name, String cutmrId) {
Item_bill.customerName = name;
Item_bill.customerId = cutmrId;
}
只有再次调用initialize()方法后才会设置值。 如何在不再次调用initialize()方法的情况下解决这个问题??
谁能帮帮我。谢谢。
最佳答案
最后我解决了这个问题, 我引用了名为 custmrNameDummy 和 idLabelDummy 的标签,
@FXML
private Label custmrName;
public static Label custmrNameDummy;
@FXML
private Label idLabel;
public static Label idLabelDummy;
static String customerName = null;
static String customerId = null;
public void initialize(URL location, ResourceBundle resources) {
custmrNameDummy=custmrName;
idLabelDummy=idLabel;
}
public static void setDataCustomer(String name, String cutmrId) {
Item_bill.customerName = name;
Item_bill.customerId = cutmrId;
custmrNameDummy.setText(customerName);
idLabelDummy.setText(String.valueOf(customerId));
}
这对我有用。
关于java - 刷新anchorpane javafx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41406160/