I have a question about the TableView element in JavaFX.
When I try to use it and add columns to it, it works fine, but if I set it to static (need to access it from another stage) the columns are not appearing at all.
My code looks like this (extracts):
@FXML
private static TableView<Datensatz> table = new TableView();
@Override
public void initialize(URL url, ResourceBundle rb) {
erstelleTabelle();
}
private static void erstelleTabelle() {
TableColumn nameColumn = new TableColumn("Name");
nameColumn.setCellValueFactory(new PropertyValueFactory<>("Name"));
TableColumn handyNrColumn = new TableColumn("Handynummer");
handyNrColumn.setCellValueFactory(new PropertyValueFactory<>("Handynummer"));
TableColumn rechnungsDatumColumn = new TableColumn("Rechnungsdatum");
rechnungsDatumColumn.setCellValueFactory(new PropertyValueFactory<>("Rechnungsdatum"));
TableColumn abrechnungsBeginnColumn = new TableColumn("Abrechnungsbeginn");
abrechnungsBeginnColumn.setCellValueFactory(new PropertyValueFactory<>("Von"));
TableColumn abrechnungsEndeColumn = new TableColumn("Abrechnungsende");
abrechnungsEndeColumn.setCellValueFactory(new PropertyValueFactory<>("Bis"));
TableColumn rechnungsnummerColumn = new TableColumn("Rechnungsnummer");
rechnungsnummerColumn.setCellValueFactory(new PropertyValueFactory<>("Rechnungsnummer"));
TableColumn betragColumn = new TableColumn("Betrag");
betragColumn.setCellValueFactory(new PropertyValueFactory<>("Betrag"));
TableColumn kostenstelleColumn = new TableColumn("Kostenstelle");
kostenstelleColumn.setCellValueFactory(new PropertyValueFactory<> ("Kostenstelle"));
TableColumn telefonKostenColumn = new TableColumn("Telefon-Kosten");
telefonKostenColumn.setCellValueFactory(new PropertyValueFactory<>("telefon"));
TableColumn smsKostenColumn = new TableColumn("SMS-Kosten");
smsKostenColumn.setCellValueFactory(new PropertyValueFactory<>("sms"));
TableColumn internetKostenColumn = new TableColumn("Internet-Kosten");
internetKostenColumn.setCellValueFactory(new PropertyValueFactory<>("internet"));
TableColumn vertragsDetailsColumn = new TableColumn("Vertragsdetails");
vertragsDetailsColumn.setCellValueFactory(new PropertyValueFactory<>("details"));
vertragsDetailsColumn.setMinWidth(100);
table.getColumns().addAll(
nameColumn,
handyNrColumn,
rechnungsDatumColumn,
abrechnungsBeginnColumn,
abrechnungsEndeColumn,
rechnungsnummerColumn,
betragColumn,
kostenstelleColumn,
telefonKostenColumn,
smsKostenColumn,
internetKostenColumn,
vertragsDetailsColumn);
}
public static void setTable(ObservableList datensatz) {
table.setItems(datensatz);
}
So when I change all static methods/variables to non-statics, everything just works fine.
Has anyone an idea what I could try to do? Thank you!