【发布时间】:2018-10-11 10:41:48
【问题描述】:
我试图只在屏幕上显示一个按钮,但每次我运行 java 程序时都没有显示。我不确定为什么什么都没有显示。
代码:
package application;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
Button button2 = new Button("Clear");
}
public static void main(String[] args) {
launch(args);
}
}
【问题讨论】:
-
本教程要求我将我的包从应用程序更改为其他东西,真的有必要吗。
-
不,只取按钮添加到场景中的部分
-
那是一个糟糕的教程。它所展示的只是如何使用
Button作为Scene的根。这个应该更适合:docs.oracle.com/javase/8/javafx/layout-tutorial/…
标签: java macos user-interface button javafx