Ahoj, neporadí mi někdo jak udělat obdobnou tabulku v JavaFx jako je tato (viz obrázek) udělaná v SWT.
Děkuji
William
Ahoj, neporadí mi někdo jak udělat obdobnou tabulku v JavaFx jako je tato (viz obrázek) udělaná v SWT.
Děkuji
William
to jsem už viděl (ten odkaz co posíláš). To je ale nepřestavitelně zbytečně složité tyto příklady s tou třídou Person. Jde mi o to, že bych potřeboval mít podobně zpracovanou tabulku (viz obrázek dole jak jsem udělal pro SWT). Je takové řešení? Jak udělat jednoduše tabulku viz hore?
public class SwtTable {
public static void main(String[] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new GridLayout());
Table table = new Table (shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible (true);
table.setHeaderVisible (true);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 200;
table.setLayoutData(data);
String[] titles = {"col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8","col9","col10"};
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (table, SWT.NONE);
column.setText (titles [i]);
}
int count = 5000;
for (int i=0; i<count; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText (0, Integer.toString(i+1));
item.setText (1, "a");
item.setText (2, "b");
item.setText (3, "c");
item.setText (4, "d");
item.setText (5, "e");
item.setText (6, "f");
item.setText (7, "g");
item.setText (8, "h");
item.setText (9, "ch");
}
for (int i=0; i<titles.length; i++) {
table.getColumn (i).pack ();
}
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Můj pokus v JavaFx. Nedaří se mi takto SIMPLY dostat do tabulky data. Kod a jeho vystup priložen.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class JavaFxTable extends Application {
private TableView<String> tableView = new TableView<String>();
private ObservableList<String> dataForTable = FXCollections.observableArrayList();
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void start(Stage primaryStage) {
Group root = new Group();
int widthOfColumn = 44;
TableColumn col1 = new TableColumn("col1");
col1.setMinWidth(widthOfColumn);
TableColumn col2 = new TableColumn("col2");
col2.setMinWidth(widthOfColumn);
TableColumn col3 = new TableColumn("col3");
col3.setMinWidth(widthOfColumn);
TableColumn col4 = new TableColumn("col4");
col4.setMinWidth(widthOfColumn);
TableColumn col5 = new TableColumn("col5");
col5.setMinWidth(widthOfColumn);
TableColumn col6 = new TableColumn("col6");
col6.setMinWidth(widthOfColumn);
TableColumn col7 = new TableColumn("col7");
col7.setMinWidth(widthOfColumn);
TableColumn col8 = new TableColumn("col8");
col8.setMinWidth(widthOfColumn);
TableColumn col9 = new TableColumn("col9");
col9.setMinWidth(widthOfColumn);
TableColumn col10 = new TableColumn("col10");
col10.setMinWidth(widthOfColumn);
tableView.setMaxSize(442, 420);
tableView.getColumns().addAll(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10);
dataForTable.addAll("1","1","1","1","1","1","1","1","1","1");
tableView.setItems(dataForTable);
VBox vBox = new VBox();
vBox.setSpacing(10);
vBox.getChildren().add(tableView);
root.getChildren().add(vBox);
primaryStage.setScene(new Scene(root, 500, 500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
#7 Flowy
Díky ale nevím proč mi to pořád nefunguje (pořád prázdná tabulka jen s názvy sloupců)
mport javafx.beans.property.SimpleStringProperty;
public class DataModel {
private final SimpleStringProperty column1;
private final SimpleStringProperty column2;
private final SimpleStringProperty column3;
private final SimpleStringProperty column4;
private final SimpleStringProperty column5;
private final SimpleStringProperty column6;
private final SimpleStringProperty column7;
private final SimpleStringProperty column8;
private final SimpleStringProperty column9;
private final SimpleStringProperty column10;
public DataModel(SimpleStringProperty column1,
SimpleStringProperty column2, SimpleStringProperty column3,
SimpleStringProperty column4, SimpleStringProperty column5,
SimpleStringProperty column6, SimpleStringProperty column7,
SimpleStringProperty column8, SimpleStringProperty column9,
SimpleStringProperty column10) {
this.column1 = column1;
this.column2 = column2;
this.column3 = column3;
this.column4 = column4;
this.column5 = column5;
this.column6 = column6;
this.column7 = column7;
this.column8 = column8;
this.column9 = column9;
this.column10 = column10;
}
public SimpleStringProperty getColumn1() {
return column1;
}
public SimpleStringProperty getColumn2() {
return column2;
}
public SimpleStringProperty getColumn3() {
return column3;
}
public SimpleStringProperty getColumn4() {
return column4;
}
public SimpleStringProperty getColumn5() {
return column5;
}
public SimpleStringProperty getColumn6() {
return column6;
}
public SimpleStringProperty getColumn7() {
return column7;
}
public SimpleStringProperty getColumn8() {
return column8;
}
public SimpleStringProperty getColumn9() {
return column9;
}
public SimpleStringProperty getColumn10() {
return column10;
}
}
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class JavaFxTable extends Application {
private TableView<DataModel> tableView = new TableView<DataModel>();
final ObservableList<DataModel> data = FXCollections.observableArrayList(
new DataModel(new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1")),
new DataModel(new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1")),
new DataModel(new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"),new SimpleStringProperty("1"))
);
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void start(Stage primaryStage) {
Group root = new Group();
int widthOfColumn = 44;
TableColumn col1 = new TableColumn("col1");
col1.setMinWidth(widthOfColumn);
TableColumn col2 = new TableColumn("col2");
col2.setMinWidth(widthOfColumn);
TableColumn col3 = new TableColumn("col3");
col3.setMinWidth(widthOfColumn);
TableColumn col4 = new TableColumn("col4");
col4.setMinWidth(widthOfColumn);
TableColumn col5 = new TableColumn("col5");
col5.setMinWidth(widthOfColumn);
TableColumn col6 = new TableColumn("col6");
col6.setMinWidth(widthOfColumn);
TableColumn col7 = new TableColumn("col7");
col7.setMinWidth(widthOfColumn);
TableColumn col8 = new TableColumn("col8");
col8.setMinWidth(widthOfColumn);
TableColumn col9 = new TableColumn("col9");
col9.setMinWidth(widthOfColumn);
TableColumn col10 = new TableColumn("col10");
col10.setMinWidth(widthOfColumn);
tableView.setMaxSize(442, 420);
tableView.getColumns().addAll(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10);
tableView.setItems(data);
VBox vBox = new VBox();
vBox.setSpacing(10);
vBox.getChildren().add(tableView);
root.getChildren().add(vBox);
primaryStage.setScene(new Scene(root, 500, 500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku