背景没有显示javaFX

时间:2017-10-17 03:03:37

标签: java javafx

我正在尝试在javaFX中创建一个开始屏幕,并为它添加一个背景,以便在按钮和文本后面。然而,它似乎并不适合我,因为我的应用程序没有显示背景。想知道出了什么问题。这是我的代码:

package calendar;

import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Calendar extends Application {

@Override
public void start(Stage primaryStage) throws IOException {



primaryStage.setTitle("JavaFX Welcome");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));

Text scenetitle = new Text("Get Started");
scenetitle.setFont(Font.font("Bookman", FontWeight.BOLD, 30));
grid.add(scenetitle, 0, 0, 2, 1);

Button start = new Button("Start");
HBox hbStart = new HBox(10);
hbStart.setAlignment(Pos.CENTER);
hbStart.getChildren().add(start);
grid.add(hbStart, 1, 10);

final Text actiontarget = new Text();
grid.add(actiontarget, 1, 6);

start.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent e) {

  }
});       

Scene scene = new Scene(grid, 800, 600);
primaryStage.setScene(scene);
scene.getStylesheets().add
 (Calendar.class.getResource("background.css").toExternalForm());
primaryStage.show();
 }

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

}

css文件的代码如下:

 .root { -fx-background-image: url("background.jpeg"); } 

任何帮助将不胜感激。我相当肯定这不是我错误放置或误导文件的问题。

0 个答案:

没有答案
相关问题