我有2个窗口。 Window1通过单击按钮启动窗口2。 我想在windows2关闭后立即在窗口1中更改TextField的文本。
一旦窗口2关闭,有没有办法在window1中创建一个事件。
我正在使用fxml,因此每个窗口都有不同的控制器和fxml文件。
第一个窗口主要是一个表视图,一些文本字段用mysql数据库连接数据,这里是代码。
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javax.print.attribute.standard.MediaSize;
import java.io.IOException;
import java.net.URL;
import java.sql.*;
import java.util.ResourceBundle;
public class TableData implements Initializable {
@FXML
private TableColumn<Data, String> COMPANYCOL;
@FXML
private TableColumn<Data, ?> DATECOL;
@FXML
private TextArea AddressField;
@FXML
private TableColumn<Data, Integer> IDCOL;
@FXML
TextField RefernceField;
@FXML
private Label searchLabel;
@FXML
private MenuItem FilterMenuItem;
@FXML
private Label FilterLabel;
@FXML
private TextField FilterField;
@FXML
private TableView<Data> TABLEVIEWID;
@FXML
private TableColumn<Data, Double> PHONENOCOL;
@FXML
private TextField SearchField;
Stage stage;
@FXML
private TableColumn<Data, String> ADDRESSCOL;
@FXML
private TextField PhoneNoField;
@FXML
private TextField NameField;
@FXML
private Button AddButton;
@FXML
private TableColumn<Data, String> NAMECOL;
@FXML
private TableColumn<Data, String> REFRENCECOL;
@FXML
private TextField CompanyField;
Stage primaryStage= new Stage();
private Config config = new Config();
ObservableList<Data> Mainlist = FXCollections.observableArrayList();
Connection drdoConnection = DatabaseConnection.getConnectionDrdo();
Connection MydatabaseConnection = DatabaseConnection.getConnectionOwn();
public TableData() throws Exception {
}
int q;
RefrenceController refrenceController= new RefrenceController();
int icno=0;
@Override
public void initialize(URL location, ResourceBundle resources) {
if(drdoConnection!=null&&MydatabaseConnection!=null) {
RefernceField.setEditable(false);
config.factory(IDCOL, "id");
config.factory(NAMECOL, "name");
config.factory(COMPANYCOL, "company");
config.factory(ADDRESSCOL, "address");
config.factory(PHONENOCOL,"phoneno");
config.factory(REFRENCECOL, "refrence");
try {
Statement statement= drdoConnection.createStatement();
ResultSet resultSet= statement.executeQuery("SELECT * FROM drdomy");
while (resultSet.next()){
q= resultSet.getInt("id");
Mainlist.addAll(new Data(q,resultSet.getString("name"),resultSet.getString("company"),
resultSet.getString("address"),resultSet.getDouble("phoneno"),resultSet.getString("Refrence")));
}
TABLEVIEWID.getItems().addAll(Mainlist);
Parent root = FXMLLoader.load(getClass().getResource("Ref.fxml"));
primaryStage.setTitle("Ref Window");
primaryStage.initModality(Modality.APPLICATION_MODAL);
primaryStage.setScene(new Scene(root));
//this is the code that is giving that nullPointerException
//I have tried Every Possible Step But Coudn't resolve it
primaryStage.setOnCloseRequest(e->{
RefernceField.setText(String.valueOf(refrenceController.OnSubmitButtonClicked()));
});
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
else {
config.alert(Alert.AlertType.ERROR, "Database Server May be Down Check Logs");
}
}
@FXML
void TableAddButtonAction(ActionEvent event) throws SQLException {
String query= "INSERT INTO drdomy (id,name,company,address,phoneno,Refrence) VALUES (?,?,?,?,?,?)";
PreparedStatement statement = drdoConnection.prepareStatement(query);
statement.setInt(1,++q);
statement.setString(2,NameField.getText());
statement.setString(3,CompanyField.getText());
statement.setString(4,AddressField.getText());
statement.setDouble(5,Double.parseDouble(PhoneNoField.getText()));
statement.setString(6,RefernceField.getText());
statement.execute();
TABLEVIEWID.getItems().clear();
Mainlist.addAll(new Data(q,NameField.getText(),CompanyField.getText(),AddressField.getText(),Double.parseDouble(String.valueOf(PhoneNoField.getText())),RefernceField.getText()));
TABLEVIEWID.getItems().addAll(Mainlist);
NameField.clear();
CompanyField.clear();
AddressField.clear();
PhoneNoField.clear();
RefernceField.clear();
statement.close();
stage = (Stage) AddButton.getScene().getWindow();
stage.setOnCloseRequest(e->{
try {
drdoConnection.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
});
}
@FXML
void FilterActionMenuItem(ActionEvent event) {
FilterField.setScaleY(1);
FilterField.setScaleX(1);
FilterField.setScaleZ(1);
FilterLabel.setScaleX(1);
FilterLabel.setScaleY(1);
FilterLabel.setScaleZ(1);
}
@FXML
void KeyRealesedFilterField() {
FilteredList<Data> dataFilteredList = new FilteredList<Data>(Mainlist,p-> true);
FilterField.textProperty().addListener((observable ,oldValue,newValue )->{
dataFilteredList.setPredicate(data -> {
if (newValue== null|| newValue.isEmpty())
return true;
String lowercase= newValue.toLowerCase();
int p=data.getId();
if (data.getAddress().toLowerCase().contains(lowercase)){
return true;
}
else if(String.valueOf(p).contains(newValue)){
return true;
}
else if(String.valueOf(data.getPhoneno()).contains(newValue))
return true;
else if (data.getRefrence().toLowerCase().contains(lowercase)){
return true;
}
else if(data.getName().toLowerCase().contains(lowercase)){
return true;
}
else if (data.getCompany().toLowerCase().contains(lowercase)){
return true;
}
return false;
});
SortedList<Data> dataSortedList = new SortedList<Data>(dataFilteredList);
dataSortedList.comparatorProperty().bind(TABLEVIEWID.comparatorProperty());
TABLEVIEWID.setItems(dataSortedList);
});
}
@FXML
void OnRefAction() throws IOException {
primaryStage.showAndWait();
}
}
所以情况是我通过手动将数据输入到文本字段来使用此场景向mysql数据库填充数据,但是refrence字段的OnAction连接到另一个场景,该场景一旦关闭就设置了引用文本字段< / p>
这是由参考字段打开的场景控制器
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javax.swing.plaf.nimbus.State;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Objects;
import java.util.ResourceBundle;
public class RefrenceController implements Initializable {
@FXML
private Button btnsubmit;
@FXML
private TableColumn<SData, String> GROUPCOL;
@FXML
private TableColumn<SData, String> DESIGCOL;
@FXML
private TextField SearchFieldS;
@FXML
private TableColumn<SData, Integer> ICNOCOL;
@FXML
private TableColumn<SData, String> NAMECOLS;
@FXML
TableView<SData> TABLEID;
private TableData tableData;
private Config config = new Config();
private int icno=0;
Connection SDRDODATA = DatabaseConnection.getConnectionOwn();
ObservableList<SData> MainListS = FXCollections.observableArrayList();
public RefrenceController() throws Exception {
}
@Override
public void initialize(URL location, ResourceBundle resources) {
config.factory(ICNOCOL, "ID");
config.factory(NAMECOLS, "NAME");
config.factory(GROUPCOL, "GROUP");
config.factory(DESIGCOL, "DESIGNATION");
try {
Statement statement = SDRDODATA.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM sdata");
while (rs.next()) {
MainListS.addAll(new SData(rs.getInt("IC_NO"), rs.getString("name"), rs.getString("GroupS"),
rs.getString("Designation")));
}
statement.close();
SDRDODATA.close();
// OnSubmitButtonClicked();
} catch (SQLException e) {
e.printStackTrace();
}
}
@FXML
void OnkeyRelesedMethod() {
FilteredList<SData> filteredData = new FilteredList<SData>(MainListS, p -> true);
SearchFieldS.textProperty().addListener((observable, oldValue, newValue) -> {
filteredData.setPredicate(sData -> {
if (newValue == null || newValue.isEmpty())
return false;
String lowercase = newValue.toLowerCase();
if (String.valueOf(sData.getID()).contains(newValue))
return true;
else if (sData.getNAME().toLowerCase().contains(lowercase))
return true;
else if (sData.getGROUP().toLowerCase().contains(lowercase))
return true;
else if (sData.getDESIGNATION().toLowerCase().contains(lowercase))
return true;
return false;
});
SortedList<SData> sortedList = new SortedList<>(filteredData);
sortedList.comparatorProperty().bind(TABLEID.comparatorProperty());
TABLEID.setItems(sortedList);
});
}
@FXML
int OnSubmitButtonClicked() {
SData sData = TABLEID.getSelectionModel().getSelectedItem();
icno = sData.getID();
Stage stage = (Stage) btnsubmit.getScene().getWindow();
}
@FXML
void OnMouseClicked() {
SData sData=TABLEID.getSelectionModel().getSelectedItem();
icno= sData.getID();
System.out.println(icno);
return icno;
}
}
我已经尝试了所有可能的步骤,但每件事都给出了nullpointerException
请告诉我如何解决这个问题。
如果需要任何解释,请询问。
这是stackTrace
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method)
at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:218)
at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511)
at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:583)
at javafx.stage.Stage.showAndWait(Stage.java:474)
at sample.TableData.OnRefAction(TableData.java:279)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at com.sun.javafx.scene.control.behavior.TextFieldBehavior.fire(TextFieldBehavior.java:179)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:178)
at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:127)
at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$74(BehaviorBase.java:135)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3964)
at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:216)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$353(GlassViewEventHandler.java:247)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:246)
at com.sun.glass.ui.View.handleKeyEvent(View.java:546)
at com.sun.glass.ui.View.notifyKey(View.java:966)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 111 more
Caused by: java.lang.NullPointerException
at sample.RefrenceController.OnSubmitButtonClicked(RefrenceController.java:129)
at sample.TableData.lambda$initialize$0(TableData.java:142)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.stage.Window.fireEvent(Window.java:1120)
at javafx.stage.Window$9.invalidated(Window.java:820)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:144)
at javafx.stage.Window.setShowing(Window.java:922)
at javafx.stage.Window.hide(Window.java:947)
at sample.RefrenceController.OnSubmitButtonClicked(RefrenceController.java:151)
... 121 more
答案 0 :(得分:1)
在关闭请求或隐藏或隐藏时设置EventHandler
。选择你需要的东西:
Stage secondaryStage = new Stage();
secondaryStage.setOnCloseRequest(ev -> {
//change text in TextField
});
secondaryStage.setOnHidden(ev -> {
//or change text in TextField
});
secondaryStage.setOnHiding(ev -> {
//or change text in TextField
});
答案 1 :(得分:1)
如果您想在窗口关闭后立即创建活动 使用即将关闭的窗口阶段使用setOnCloseRequest。