因此,我试图显示此窗口。这给我关于未为Button类型定义的方法的错误。我不确定为什么,因为此代码是直接从教程中复制的。在他的IDE上工作,但不在我的工作中。他正在使用intellij,而我正在使用Eclipse。
closeButton.setOnAction(e -> window.close());
Run Code Online (Sandbox Code Playgroud)
该
setOnAction((<no type> e) -> {})类型的方法未定义Button
layout.getChildren().addAll(label, closeButton);
Run Code Online (Sandbox Code Playgroud)
addAll(int, Collection<? extends Node>)类型中的方法List<Node>不适用于参数(Label, Button)“
import java.awt.Button;
...
public static void display(String title, String message) {
Stage window = new Stage();
//Block events to other windows
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(250);
Label label = new Label();
label.setText(message);
Button closeButton = new Button("Close this window");
closeButton.setOnAction(e -> window.close());
VBox layout = new VBox(10);
layout.getChildren().addAll(label, closeButton);
layout.setAlignment(Pos.CENTER);
//Display window and wait for it to be closed before returning
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
}
Run Code Online (Sandbox Code Playgroud)
您使用了错误的Button类。Button您要引用的类是AWTButton。相反,您应该使用JavaFXButton。
将导入语句更改为以下内容:
import javafx.scene.control.Button;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1302 次 |
| 最近记录: |