如何使用JavaFX 2.0PopupWindow
或Popup
从 JavaFX 2.0 显示弹出窗口?我找不到任何教程或示例。
问问题
6935 次
1 回答
4
public class test extends Application{
Stage primaryStage;
@Override
public void start(final Stage stage) throws Exception {
primaryStage = stage;
Button showPopUp = new Button("Pop Up");
final TextField name = new TextField();
VBox vBox = new VBox();
vBox.getChildren().add(name);
vBox.getChildren().add(showPopUp);
final Label hello = new Label();
final TextField name2 = new TextField();
Button ok = new Button("ok");
Button cencel = new Button("cancel");
VBox popUpVBox = new VBox();
popUpVBox.getChildren().add(hello);
popUpVBox.getChildren().add(name2);
popUpVBox.getChildren().add(ok);
popUpVBox.getChildren().add(cencel);
final Popup popup = new Popup();
popup.setAutoFix(false);
popup.setHideOnEscape(true);
popup.getContent().addAll(popUpVBox);
popup.setX(250);
popup.setY(175);
ok.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
name.setText(name2.getText());
}
});
cencel.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
popup.hide();
}
});
showPopUp.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
if (popup.isShowing()) {
popup.hide();
} else {
hello.setText("hello.."+name.getText());
popup.show(stage);
}
}
});
Scene scene = new Scene(vBox);
primaryStage.setScene(scene);
primaryStage.setWidth(200);
primaryStage.setHeight(200);
primaryStage.show();
}
}
于 2012-11-06T10:14:28.307 回答