I have defined a css stylesheet in my FXML file, which when opened with scenebuilder, it's displayed correctly, but when I run the program, it isn't. This confuses me...
This is what I'm working with:
├───bin
│ └───app
│ application.css
│ Fxml.fxml
│ Main.class
│
└───src
└───app
application.css
Fxml.fxml
Main.java
My Fxml.fxml file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import java.net.URL?>
<VBox prefHeight="100.0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox prefHeight="20.0" />
<TableView id="table" xmlns:fx="http://javafx.com/fxml">
<columns>
<TableColumn id="tablec_h_from" text="H_FROM" />
<!-- other columns -->
</columns>
</TableView>
</children>
<stylesheets>
<URL value="@application.css" />
</stylesheets>
</VBox>
The application.css looks like this:
.table-column {
-fx-pref-width: 55;
}
The Main.java:
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
VBox root = null;
try {
root = (VBox)FXMLLoader.load(getClass().getResource("Fxml.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
}
So, as I said earlier, when I open my FXML file with scene builder, the table columns are of the proper width of 55px, but when I run the program, the table columns are of a default width of 80 px. The goal is of course to have the width of the columns 55px.
Do I have to import the css file in Main.java, even if I've defined it in the fxml file? And if so, how?
I'm using eclipse IDE, and JavaFX version 2.2.45-b18
Any help is appreciated.