import javafx.application.Application; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.stage.Stage; public class TabelleMehrspaltig extends Application { private TableView tView = new TableView(); @SuppressWarnings("unchecked") @Override public void start(Stage stage) { stage.setTitle("Modeds"); stage.setWidth(350); stage.setHeight(300); tView.setEditable(true); TableColumn nameCol = new TableColumn( "Name"); nameCol.setCellValueFactory((p) -> { return p.getValue().nameProperty(); }); nameCol.prefWidthProperty().bind(tView.widthProperty().multiply(0.45)); TableColumn bjCol = new TableColumn( "Baujahr"); bjCol.setCellValueFactory((p) -> { return p.getValue().baujahrProperty().asObject(); }); bjCol.prefWidthProperty().bind(tView.widthProperty().multiply(0.2)); TableColumn psCol = new TableColumn( "PS"); psCol.setCellValueFactory((p) -> { return p.getValue().psProperty().asObject(); }); psCol.prefWidthProperty().bind(tView.widthProperty().multiply(0.1)); TableColumn ccmCol = new TableColumn( "Hubraum"); ccmCol.setCellValueFactory((p) -> { return p.getValue().hubraumProperty().asObject(); }); ccmCol.prefWidthProperty().bind(tView.widthProperty().multiply(0.25)); tView.getColumns().addAll(nameCol, bjCol, psCol, ccmCol); tView.setItems(createList()); Scene scene = new Scene(tView); stage.setScene(scene); stage.show(); } private ObservableList createList() { final ObservableList mopeds = FXCollections.observableArrayList( new Moped("Norton Manx", 1954, 53, 500), new Moped("Moto Guzzi V8", 1957, 72, 500), new Moped("BMW RS", 1953, 60, 500), new Moped("Megola", 1924, 14, 640), new Moped("B\u00F6hmerland", 1939, 24, 600)); return mopeds; } public static void main(String[] args) { launch(args); } } public class Moped { private StringProperty name; private IntegerProperty baujahr, ps, hubraum; public Moped(String name, int baujahr, int ps, int hubraum) { this.name = new SimpleStringProperty(name); this.baujahr = new SimpleIntegerProperty(baujahr); this.ps = new SimpleIntegerProperty(ps); this.hubraum = new SimpleIntegerProperty(hubraum); } public int getHubraum() { return hubraum.get(); } public IntegerProperty hubraumProperty() { if (hubraum == null) hubraum = new SimpleIntegerProperty(-1); return hubraum; } public void setHubraum(int hubraum) { this.hubraum.set(hubraum); } public int getPs() { return ps.get(); } public IntegerProperty psProperty() { if (ps == null) ps = new SimpleIntegerProperty(-1); return ps; } public void setPs(int ps) { this.ps.set(ps); } public int getBaujahr() { return baujahr.get(); } public IntegerProperty baujahrProperty() { if (baujahr == null) baujahr = new SimpleIntegerProperty(-1); return baujahr; } public void setBaujahr(int baujahr) { this.baujahr.set(baujahr); } public String getName() { return name.get(); } public StringProperty nameProperty() { if (name == null) name = new SimpleStringProperty("-"); return name; } public void setName(String name) { this.name.set(name); } }