Bin neu mit Erstellen von Java GUIs. Ich habe heute auch zum ersten Mal mit FXML bzw. dem Scene Builder gearbeitet. Auf verschiedene Weisen habe ich versucht mein Stylesheet (src/sample/stylesheet.css) einzubinden. Ich plage mich damit nun schon eine Weile herum und rege mich unheimlich darüber auf. Es wäre toll wenn mir jemand schnell einfach sagen könnte woran es scheitert!!!
Aktuell hab ich
Aktuell hab ich
Java:
scene.getStylesheets().add("stylesheet.css");
Java:
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Mein Spiel");
Scene scene = new Scene(root);
scene.getStylesheets().add("/sample/stylesheet.css");
primaryStage.setScene(scene);
primaryStage.show();
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.shape.Rectangle?>
<GridPane alignment="center" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints maxWidth="196.0" minWidth="144.0" prefWidth="153.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints />
<RowConstraints />
</rowConstraints>
<children>
<Pane prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #42bff4;" />
<Pane prefHeight="400.0" prefWidth="200.0" style="-fx-background-color: #b56805;" GridPane.columnIndex="2">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="50.0" layoutX="20.0" layoutY="31.0" styleClass="shop-item-box" width="50.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="50.0" layoutX="89.0" layoutY="31.0" styleClass="shop-item-box" width="50.0" />
</children>
</Pane>
</children>
</GridPane>
CSS:
.shop-item-box {
-fx-background-color: yellow !important;
}
Zuletzt bearbeitet: