Quite frustrating as I follow guidelines and basic tutorial. I can apply CSS styles to differnt elements but not to vbox or hbox.
I have the following simple Apps creating a simple scene using a FMXL and CSS:
import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class BingRen extends Application {
@Override
public void start(Stage primaryStage) {
Parent root = null;
FXMLLoader loader = new FXMLLoader();
URL xmlUrl = getClass().getResource("/BingRen.fxml");
loader.setLocation(xmlUrl);
try {
root = loader.load();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("BingRen.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
With FXML, creating just a BordPane and 2 HBox containing one label each. Almost as simple as HellopApp :
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>
<BorderPane fx:id="rootBorderPane"
xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="MainControler">
<top>
<HBox>
<Label text="BingRen app" />
</HBox>
</top>
<bottom>
<HBox>
<Label text="Status bar" />
</HBox>
</bottom>
<center>
</center>
</BorderPane>
And CSS to set some basic properties:
.hbox {
-fx-background-color: #00ff00;
-fx-border-color: #00ff00;
-fx-border-width: 2px;
-fx-padding: 10;
-fx-spacing: 8;
}
.label {
-fx-text-fill: #0000ff;
}
Label properly turn blue but not of the hbox style are applied
In fact none of the suggestion worked.
I tried :
- Change .hbox to .Hbox in css file
- Make a #allbox in css file and add fx-id="allbox" and fxml file
For every change, I change the color for label to ensure the new version of css is read through.
Label always change color but I never get backgroung or paddings in the Hboxes