Dies ist eine alte Version des Dokuments!
Table, Tabellen
Die Verwendung von Tabellen in JavaFX zeigt folgendes Bespiel:
package com.sowas.javawiki.javafx; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.stage.Stage; public class MyFxApplication extends Application { @Override public void start(Stage mainStage) { mainStage.setTitle("JavaFX-Table"); ObservableList<RowData> data = FXCollections.observableArrayList( new RowData("col 1/row 1", "col 2/row1", "col 3/row1"), new RowData("col 1/row 2", "col 2/row2", "col 3/row2"), new RowData("col 1/row 3", "col 2/row3", "col 3/row3") ); TableView<RowData> table = new TableView<RowData>(); TableColumn col1 = new TableColumn("Col 1"); col1.setCellValueFactory(new PropertyValueFactory<RowData, String>("colValue1")); TableColumn col2 = new TableColumn("Col 2"); col2.setCellValueFactory(new PropertyValueFactory<RowData, String>("colValue2")); TableColumn col3 = new TableColumn("Col 3"); col3.setCellValueFactory(new PropertyValueFactory<RowData, String>("colValue3")); table.getColumns().addAll(col1, col2, col3); table.setItems(data); Scene scene = new Scene(table); mainStage.setScene(scene); mainStage.show(); } public static void main(String[] args) { launch(args); } }
package com.sowas.javawiki.javafx;
import javafx.beans.property.SimpleStringProperty;
public class RowData {
private SimpleStringProperty colValue1;
private SimpleStringProperty colValue2;
private SimpleStringProperty colValue3;
public RowData(String colValue1, String colValue2, String colValue3) {
this.colValue1 = new SimpleStringProperty(colValue1);
this.colValue2 = new SimpleStringProperty(colValue2);
this.colValue3 = new SimpleStringProperty(colValue3);
}
public String getColValue1() {
return colValue1.get();
}
public String getColValue2() {
return colValue3.get();
}
public String getColValue3() {
return colValue3.get();
}
}
Stichworte:
JavaFX Table, Tabellen, Beispiel