VBox txts = new VBox();
HBox textfieldBox1 = new HBox();
textfieldBox1.setSpacing(10);
textfieldBox1.setPadding(new Insets(10));
Menu item1 = new Menu("test submenu");
MenuItem subMenuItem1 = new MenuItem("Sub Menu Item 1");
MenuItem subMenuItem2 = new MenuItem("Sub Menu Item 2");
MenuItem subMenuItem3 = new MenuItem("Sub Menu Item 3");
item1.getItems().addAll(subMenuItem1, subMenuItem2, subMenuItem3);
TextField tf1 = new TextField("Textfield");
ContextMenu cm = new ContextMenu(new MenuItem("test"), item1, new MenuItem("test"));
tf1.setContextMenu(cm);
textfieldBox1.getChildren().add(tf1);
TextField tf2 = new TextField();
textfieldBox1.getChildren().add(tf2);
HBox textfieldBox2 = new HBox();
textfieldBox2.setSpacing(10);
textfieldBox2.setPadding(new Insets(10));
TextField tf3 = new TextField("disabled Textfield");
tf3.setDisable(true);
tf3.setEditable(false);
textfieldBox2.getChildren().add(tf3);
TextField tf4 = new TextField();
tf4.setPromptText("prompt text");
textfieldBox2.getChildren().add(tf4);
txts.getChildren().add(textfieldBox2);
HBox textfieldBox3 = new HBox();
textfieldBox3.setSpacing(10);
textfieldBox3.setPadding(new Insets(10));
TextField tf5 = new TextField("non-editable textfield");
tf5.setEditable(false);
textfieldBox3.getChildren().add(tf5);
PasswordField pw1 = new PasswordField();
pw1.setText("password");
textfieldBox3.getChildren().add(pw1);
txts.getChildren().add(textfieldBox3);
VBox textareaBox = new VBox();
textareaBox.setSpacing(10);
textareaBox.setPadding(new Insets(10));
TextArea area = new TextArea();
area.setPromptText("TextArea with promptText");
area.setPrefWidth(290);
area.setPrefHeight(50);
area.setPrefColumnCount(80);
textareaBox.getChildren().add(area);
TextArea area2 = new TextArea();
area2.setText("Disabled");
area2.setDisable(true);
area2.setPrefWidth(290);
area2.setPrefHeight(50);
textareaBox.getChildren().add(area2);
txts.getChildren().add(textareaBox);
tabTexts.setContent(txts);
buttonTabPane.getTabs().add(tabTexts);
pane.setCenter(buttonTabPane);
TabPane tabPane = new TabPane();
Tab tabChoiceBox = new Tab();
tabChoiceBox.setText("Combo- etc");
VBox collectorVBox = new VBox();
HBox choiceBoxBox = new HBox();
choiceBoxBox.setSpacing(10);
choiceBoxBox.setPadding(new Insets(10));
ChoiceBox<String> choices = new ChoiceBox<String>(FXCollections.observableArrayList("4", "10", "12"));
choices.getSelectionModel().selectFirst();
choiceBoxBox.getChildren().add(choices);
ChoiceBox<String> choices2 = new ChoiceBox<String>(FXCollections.observableArrayList("A", "B", "C"));
choices2.getSelectionModel().selectFirst();
choices2.setDisable(true);
choiceBoxBox.getChildren().add(choices2);
collectorVBox.getChildren().add(choiceBoxBox);
ObservableList<String> items = FXCollections.observableArrayList("A", "B", "C");
HBox editableComboBoxBox =new HBox();
editableComboBoxBox.setSpacing(10);
editableComboBoxBox.setPadding(new Insets(10));
ComboBox<String> combo1 = new ComboBox<String>(items);
combo1.setEditable(true);
editableComboBoxBox.getChildren().add(combo1);
ComboBox<String> combo2 = new ComboBox<String>(items);
combo2.setDisable(true);
combo2.setEditable(true);
editableComboBoxBox.getChildren().add(combo2);
collectorVBox.getChildren().add(editableComboBoxBox);
HBox comboBoxBox = new HBox();
comboBoxBox.setSpacing(10);
comboBoxBox.setPadding(new Insets(10));
ComboBox<String> combo3 = new ComboBox<String>(items);
combo3.setPromptText("test");
combo3.setEditable(false);
comboBoxBox.getChildren().add(combo3);
ComboBox<String> combo4 = new ComboBox<String>(items);
combo4.setPromptText("test");
combo4.setEditable(false);
combo4.setDisable(true);
comboBoxBox.getChildren().add(combo4);
collectorVBox.getChildren().add(comboBoxBox);
HBox colorPickerBox = new HBox();
colorPickerBox.setSpacing(10);
colorPickerBox.setPadding(new Insets(10));
ColorPicker color = new ColorPicker(Color.rgb(194, 222, 254));
colorPickerBox.getChildren().add(color);
ColorPicker color2 = new ColorPicker(Color.rgb(194, 222, 254));
color2.getStyleClass().add("button");
colorPickerBox.getChildren().add(color2);
ColorPicker color3 = new ColorPicker(Color.rgb(194, 222, 254));
color3.getStyleClass().add("split-button");
colorPickerBox.getChildren().add(color3);
collectorVBox.getChildren().add(colorPickerBox);
tabChoiceBox.setContent(collectorVBox);
tabPane.getTabs().add(tabChoiceBox);
Tab tabHTMLBox = new Tab();
tabHTMLBox.setText("HTML");
VBox htmlbox = new VBox();
htmlbox.setPadding(new Insets(5));
HTMLEditor htmlEditor = new HTMLEditor();
htmlEditor.setPrefHeight(200);
htmlEditor.setPrefWidth(300);
htmlbox.getChildren().add(htmlEditor);
tabHTMLBox.setContent(htmlbox);
tabPane.getTabs().add(tabHTMLBox);
Tab tabSliderBox = new Tab();
tabSliderBox.setText("Sliders");
HBox slidersBox = new HBox();
slidersBox.setSpacing(10);
slidersBox.setPadding(new Insets(10));
Slider vSlider = new Slider();
vSlider.setOrientation(Orientation.VERTICAL);
slidersBox.getChildren().add(vSlider);
Slider vTickSlider = new Slider();
vTickSlider.setMin(0);
vTickSlider.setMax(100);
vTickSlider.setValue(40);
vTickSlider.setShowTickLabels(true);
vTickSlider.setShowTickMarks(true);
vTickSlider.setMajorTickUnit(50);
vTickSlider.setMinorTickCount(4);
vTickSlider.setBlockIncrement(10);
vTickSlider.setOrientation(Orientation.VERTICAL);
slidersBox.getChildren().add(vTickSlider);
VBox horizontalSliderBox = new VBox();
horizontalSliderBox.setSpacing(10);
horizontalSliderBox.setPadding(new Insets(10));
Slider simpleSlider = new Slider();
horizontalSliderBox.getChildren().add(simpleSlider);
Slider slider = new Slider();
slider.setMin(0);
slider.setMax(100);
slider.setValue(40);
slider.setShowTickLabels(true);
slider.setShowTickMarks(true);
slider.setMajorTickUnit(50);
slider.setMinorTickCount(4);
slider.setBlockIncrement(10);
horizontalSliderBox.getChildren().add(slider);
Slider simpleDisabledSlider = new Slider();
simpleDisabledSlider.setDisable(true);
horizontalSliderBox.getChildren().add(simpleDisabledSlider);
Slider disabledSlider = new Slider();
disabledSlider.setMin(0);
disabledSlider.setMax(100);
disabledSlider.setValue(40);
disabledSlider.setShowTickLabels(true);
disabledSlider.setShowTickMarks(true);
disabledSlider.setMajorTickUnit(50);
disabledSlider.setMinorTickCount(4);
disabledSlider.setBlockIncrement(10);
disabledSlider.setDisable(true);
horizontalSliderBox.getChildren().add(disabledSlider);
slidersBox.getChildren().add(horizontalSliderBox);
tabSliderBox.setContent(slidersBox);
tabPane.getTabs().add(tabSliderBox);
Tab tabTableBox = new Tab();
tabTableBox.setText("Table");
// Create a table..
HBox tableContainer = new HBox();
tableContainer.setPadding(new Insets(10));
TableView<Person> table = new TableView<Person>();
table.setPrefHeight(250);
table.setPrefWidth(650);
table.setEditable(true);
// table.getSelectionModel().setCellSelectionEnabled(true) ;
TableColumn<Person, String> firstNameCol = new TableColumn<Person, String>("First Name");
// firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setEditable(true);
lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
lastNameCol.setOnEditCommit(new EventHandler<CellEditEvent<Person, String>>() {
@Override public void handle(CellEditEvent<Person, String> t) {
((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setLastName(t.getNewValue());
}
});
lastNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
// TableColumn emailCol = new TableColumn("Email");
TableColumn<Person, String> firstEmailCol = new TableColumn<Person, String>("Primary");
// firstEmailCol.setMinWidth(200);
firstEmailCol.setCellValueFactory(new PropertyValueFactory<Person, String>("primaryEmail"));
TableColumn<Person, String> secondEmailCol = new TableColumn<Person, String>("Secondary");
// secondEmailCol.setMinWidth(200);
secondEmailCol.setCellValueFactory(new PropertyValueFactory<Person, String>("secondaryEmail"));
// emailCol.getColumns().addAll(firstEmailCol, secondEmailCol);
TableColumn<Person, Boolean> vipCol = new TableColumn<Person, Boolean>("VIP");
vipCol.setEditable(true);
vipCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Person, Boolean>, ObservableValue<Boolean>>() {
@Override public ObservableValue<Boolean> call(
javafx.scene.control.TableColumn.CellDataFeatures<Person, Boolean> param) {
return new ReadOnlyBooleanWrapper(param.getValue().getVip());
}
});
vipCol.setCellFactory(CheckBoxTableCell.forTableColumn(vipCol));
vipCol.setOnEditCommit(new EventHandler<CellEditEvent<Person, Boolean>>() {
@Override public void handle(CellEditEvent<Person, Boolean> t) {
((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setVip(t.getNewValue());
}
});
table.getColumns().addAll(firstNameCol, lastNameCol, firstEmailCol, secondEmailCol, vipCol);
table.setItems(data);
table.setTableMenuButtonVisible(true);
tableContainer.getChildren().add(table);
tabTableBox.setContent(tableContainer);
tabPane.getTabs().add(tabTableBox);
Tab tabTreeBox = new Tab();
tabTreeBox.setText("Tree");
HBox treeContainer = new HBox();
treeContainer.setPadding(new Insets(10));
TreeItem<String> rootItem = new TreeItem<String>("People");
rootItem.setExpanded(true);
for (Person person : data) {
TreeItem<String> personLeaf = new TreeItem<String>(person.getFirstName());
boolean found = false;
for (TreeItem<String> statusNode : rootItem.getChildren()) {
if (statusNode.getValue().equals((!person.getVip() ? "no " : "") + "VIP")) {
statusNode.getChildren().add(personLeaf);
found = true;
break;
}
}
if (!found) {
TreeItem<String> statusNode = new TreeItem<String>((!person.getVip() ? "no " : "") + "VIP");
rootItem.getChildren().add(statusNode);
statusNode.getChildren().add(personLeaf);
}
}
TreeView<String> tree = new TreeView<String>(rootItem);
tree.setPrefHeight(250);
tree.setPrefWidth(400);
treeContainer.getChildren().add(tree);
tabTreeBox.setContent(treeContainer);
tabPane.getTabs().add(tabTreeBox);
Tab tabTreeTableBox = new Tab();
tabTreeTableBox.setText("TreeTable");
HBox treeTableContainer = new HBox();
treeTableContainer.setPadding(new Insets(10));
TreeItem<Person> rootTreeTableItem = new TreeItem<Person>(new Person("Chef", "Chef", "chef@business.de", "chef@business.de", true));
rootTreeTableItem.setExpanded(true);
for (Person person : data) {
TreeItem<Person> personLeaf = new TreeItem<Person>(person);
boolean found = false;
for (TreeItem<Person> statusNode : rootTreeTableItem.getChildren()) {
if (statusNode.getValue().getVip() == person.getVip()) {
statusNode.getChildren().add(personLeaf);
found = true;
break;
}
}
if (!found) {
TreeItem<Person> statusNode = new TreeItem<Person>(person);
rootTreeTableItem.getChildren().add(statusNode);
statusNode.getChildren().add(personLeaf);
}
}
TreeTableView<Person> treeTable = new TreeTableView<Person>(rootTreeTableItem);
TreeTableColumn<Person, String> firstNameTreeCol = new TreeTableColumn<Person, String>("First Name");
firstNameTreeCol.setPrefWidth(100);
firstNameTreeCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
@Override public ObservableValue<String> call(CellDataFeatures<Person, String> param) {
return new ReadOnlyStringWrapper(param.getValue().getValue().getFirstName());
}
});
TreeTableColumn<Person, String> lastNameTreeCol = new TreeTableColumn<Person, String>("Last Name");
lastNameTreeCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
@Override public ObservableValue<String> call(CellDataFeatures<Person, String> param) {
return new ReadOnlyStringWrapper(param.getValue().getValue().getLastName());
}
});
TreeTableColumn<Person, String> primaryMailCol = new TreeTableColumn<Person, String>("primary Mail");
primaryMailCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
@Override public ObservableValue<String> call(CellDataFeatures<Person, String> param) {
return new ReadOnlyStringWrapper(param.getValue().getValue().getPrimaryEmail());
}
});
TreeTableColumn<Person, Boolean> vipTreeTableCol = new TreeTableColumn<Person, Boolean>("VIP");
vipTreeTableCol.setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(vipTreeTableCol));
vipTreeTableCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, Boolean>, ObservableValue<Boolean>>() {
@Override public ObservableValue<Boolean> call(CellDataFeatures<Person, Boolean> param) {
return new ReadOnlyBooleanWrapper(param.getValue().getValue().getVip());
}
});
treeTable.getColumns().setAll(firstNameTreeCol, lastNameTreeCol, primaryMailCol, vipTreeTableCol);
treeTable.setPrefHeight(250);
treeTable.setPrefWidth(600);
treeTableContainer.getChildren().add(treeTable);
tabTreeTableBox.setContent(treeTableContainer);
tabPane.getTabs().add(tabTreeTableBox);
Tab tabListBox = new Tab();
tabListBox.setText("List");
HBox listContainer = new HBox();
listContainer.setSpacing(10);
listContainer.setPadding(new Insets(10));
ListView<String> list = new ListView<String>();
ObservableList<String> listItems = FXCollections.observableArrayList("Item 1", "Item 2", "Item 3", "Item 4");
list.setItems(listItems);
list.setPrefWidth(150);
list.setPrefHeight(70);
listContainer.getChildren().add(list);
TableView<Person> listTable = new TableView<Person>();
listTable.getStyleClass().add("hide-header");
listTable.setPrefHeight(250);
listTable.setPrefWidth(150);
TableColumn<Person, String> firstNameListCol = new TableColumn<Person, String>("First Name");
firstNameListCol.setMinWidth(100);
firstNameListCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
listTable.getColumns().add(firstNameListCol);
listTable.setItems(data);
listTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
listContainer.getChildren().add(listTable);
ListView<String> horizontalList = new ListView<String>();
horizontalList.setItems(listItems);
horizontalList.setPrefWidth(150);
horizontalList.setPrefHeight(50);
horizontalList.setOrientation(Orientation.HORIZONTAL);
listContainer.getChildren().add(horizontalList);
tabListBox.setContent(listContainer);
tabPane.getTabs().add(tabListBox);
tabPane.getSelectionModel().select(tabListBox);
pane.setBottom(tabPane);
Scene myScene = new Scene(pane, 700, 600);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu("File");
menuFile.getItems().addAll(new MenuItem("New"), new MenuItem("Open File..."));
Menu menuEdit = new Menu("Edit");
menuEdit.getItems().addAll(new MenuItem("Undo"), new MenuItem("Redo"));
Menu menuView = new Menu("View");
menuView.getItems().addAll(new MenuItem("Zoom In"), new MenuItem("Zoom Out"));
menuBar.getMenus().addAll(menuFile, menuEdit, menuView);
pane.getChildren().add(menuBar);
AquaFx.style();
stage.setTitle("AquaFX");