JavaFX 2.0 TableViewBuilder, how to use - java

Given a Person class:
public class Person {
private StringProperty firstName;
private StringProperty lastName;
public Person(String firstName, String lastName){
setFirstName(firstName);
setLastName(lastName);
}
//SETTERS
public final void setFirstName(String value) { firstNameProperty().set(value); }
public final void setLastName(String value) { lastNameProperty().set(value); }
//GETTERS
public String getFirstName() { return firstNameProperty().get(); }
public String getLastName() { return lastNameProperty().get(); }
//PROPERTY GETTERS
public StringProperty firstNameProperty() {
if (firstName == null) firstName = new SimpleStringProperty(this, "firstName");
return firstName;
}
public StringProperty lastNameProperty() {
if (lastName == null) lastName = new SimpleStringProperty(this, "lastName");
return lastName;
}
}
I recreated the JavaFX API example on TableView:
public class TestTableViewBuilder extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("Jacob", "Smith"),
new Person("Isabella", "Johnson"),
new Person("Ethan", "Williams"),
new Person("Emma", "Jones"),
new Person("Michael", "Brown")
);
TableView<Person> table = new TableView<Person>();
table.setItems(data);
TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
TableColumn<Person,String> lastNameCol = new TableColumn<Person,String>("Last Name");
lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
table.getColumns().setAll(firstNameCol, lastNameCol);
Group root = new Group();
root.getChildren().add(table);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
I've been trying without success to use the TableViewBuilder to recreate the same table. Anyone have an idea how to use JavaFX 2.0 TableViewBuilder to create a TableView with an existing ObservableList?

Here is a sample:
import javafx.application.Application;
import javafx.collections.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class TableViewBuilderExample extends Application {
public static void main(String[] args) { launch(args); }
#Override public void start(Stage stage) {
final ObservableList<?> data = FXCollections.observableArrayList(
new Person("Jacob", "Smith"),
new Person("Isabella", "Johnson")
);
stage.setScene(
new Scene(
TableViewBuilder.create().items((ObservableList<Object>) data).columns(
TableColumnBuilder.create().text("First Name").cellValueFactory(new PropertyValueFactory("firstName")).build(),
TableColumnBuilder.create().text("Last Name").cellValueFactory(new PropertyValueFactory("lastName")).build()
).build()
)
);
stage.show();
}
}
There are some strange things going on with the generic type usage in the Builders. I would have liked instead to say something like TableViewBuilder<Person>.create(), but TableViewBuilder has a recursive type as a second generic type parameter which must be supplied to it, so I could not get that strategy to work. The code above is next best thing I could come up with, but it still have some strange typing going on with the ObservableList<?> definition of the data and the need to cast the data to an ObservableList<Object> in the Builder.
Based on Sergey's insight for a type parameterization syntax for the builders I was able to create the following builder which will work with a data type of ObservableList<Person>
TableViewBuilder.<Person>create().items(data).columns(
TableColumnBuilder.<Person, String>create()
.text("First Name").cellValueFactory(new PropertyValueFactory("firstName"))
.build(),
TableColumnBuilder.<Person, String>create()
.text("Last Name").cellValueFactory(new PropertyValueFactory("lastName"))
.build()
).build()
After this exercise, I would be even more inclined to checkout the DataFX project if I had to do this kind of stuff a lot . . .

The trick here is in the fact that Builders are created by factories named create, so you have to parametrize them, not the Builder class name itself which only plays namespace role here.
This way:
TableViewBuilder.<Person>create().build();

Related

Accessing nested properties in JavaFx TableView / TableColumn

I havea TableView, and I access properties of the list's objects as follows. This works just fine.
<TableColumn fx:id="dateColumn" editable="false" prefWidth="135.0" text="Date">
<cellValueFactory>
<PropertyValueFactory property="date" />
</cellValueFactory>
</TableColumn>
However, I'd like to access a nested property of the object, for example:
<TableColumn prefWidth="100.0" text="Course">
<cellValueFactory>
<PropertyValueFactory property="house.bathroom"/>
</cellValueFactory>
</TableColumn>
where my list object has a getHouse(), and House has a getBathroom(). Unfortunately, this doesn't work. I've tried a few spelling variations, but no luck.
I don't believe you can do this via FXML (though I could be wrong).
Assuming you're using proper JavaFX properties, you'd just setup your own CellValueFactory in the controller like so:
bathroomColumn.setCellValueFactory(tf -> tf.getValue().getHouse().bathroomProperty());
Since it's unclear what you want to display in the bathroom column, this would return the BathroomProperty.
If, however, you wanted to return a property within the Bathroom object, you'd simply call getBathroom().yourProperty() as well:
bathroomColumn.setCellValueFactory(tf -> tf.getValue().getHouse().getBathroom().myStringProperty());
Perhaps an example might help to demonstrate the concept:
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
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 TableViewValues extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
// Simple Interface
VBox root = new VBox(10);
root.setAlignment(Pos.CENTER);
root.setPadding(new Insets(10));
// Simple TableView
TableView<Person> personTableView = new TableView<>();
TableColumn<Person, String> colName = new TableColumn<>("Name");
TableColumn<Person, String> colCar = new TableColumn<>("Car");
// Setup the CellValueFactories
colName.setCellValueFactory(tf -> tf.getValue().nameProperty());
colCar.setCellValueFactory(tf -> tf.getValue().getCar().modelProperty());
personTableView.getColumns().addAll(colName, colCar);
root.getChildren().add(personTableView);
// Sample Data
personTableView.getItems().addAll(
new Person("Jack", new Car("Accord")),
new Person("John", new Car("Mustang")),
new Person("Sally", new Car("Yugo"))
);
// Show the stage
primaryStage.setScene(new Scene(root));
primaryStage.setTitle("Sample");
primaryStage.show();
}
}
class Person {
private final StringProperty name = new SimpleStringProperty();
private final ObjectProperty<Car> car = new SimpleObjectProperty<>();
public Person(String name, Car car) {
this.name.set(name);
this.car.set(car);
}
public String getName() {
return name.get();
}
public void setName(String name) {
this.name.set(name);
}
public StringProperty nameProperty() {
return name;
}
public Car getCar() {
return car.get();
}
public void setCar(Car car) {
this.car.set(car);
}
public ObjectProperty<Car> carProperty() {
return car;
}
}
class Car {
private final StringProperty model = new SimpleStringProperty();
public Car(String model) {
this.model.set(model);
}
public String getModel() {
return model.get();
}
public void setModel(String model) {
this.model.set(model);
}
public StringProperty modelProperty() {
return model;
}
}
The Result:
If you're using plain Java beans, the process is similar. But instead of setting the CellValueProperty to a Property within your data model classes, you'd create a new StringProperty inline and pass it the bean value you need.
So, in the Car example above, you'd do this instead:
colName.setCellValueFactory(tf -> new SimpleStringProperty(tf.getValue().getName()));
colCar.setCellValueFactory(tf -> new SimpleStringProperty(tf.getValue().getCar().getModel()));
Side Note: The tf you see referenced above is just a variable I use to refer to the CellDataFeatures object in Java which we can use to get a reference to that row's data model object (using the getValue() method). Perhaps cdf would be a better choice, but habits are hard to break.

JavaFX bind choicebox to a property in a collection

With JavaFX, what is the best way to bind ChoiceBox to properties of a collection?
In example below I try to bind ChoiceBox elements to name of an ObservableList beans. This works fine when items are added/removed but not when the property value name change.
I was hoping there is a clean and simple solution to this but haven't yet found any example of it...
The class ExampleBean2 in deliberately not implemented with properties since that object may correspond to a external model class out of my control.
package com.playground;
import org.controlsfx.control.PropertySheet;
import org.controlsfx.property.BeanPropertyUtils;
import javafx.application.Application;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class BindingPlayGround extends Application{
public static void main(String[] args) {
launch();
}
#Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("FXPlayGround");
Parent content = createContentPane();
Scene scene = new Scene(content, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
protected Parent createContentPane() {
ObservableList<BeanExample2> beans = FXCollections.observableArrayList();
ObservableList<PropertySheet> sheets = FXCollections.observableArrayList();
ListView<PropertySheet> listView = new ListView<PropertySheet>(sheets);
Button addBeanButton = new Button("Add Bean");
addBeanButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
BeanExample2 e = new BeanExample2();
e.setName("Name-not-set");
PropertySheet propertySheet = new PropertySheet(BeanPropertyUtils.getProperties(e));
sheets.add(propertySheet);
beans.add(e);
}
});
VBox vBar = new VBox();
vBar.getChildren().add(listView);
vBar.getChildren().add(addBeanButton);
ObservableList<BeanExample2> names = FXCollections.observableArrayList(new Callback<BeanExample2, Observable[]>() {
#Override
public Observable[] call(BeanExample2 param) {
return new Observable[]{new SimpleStringProperty(param, "name")};
}
});
Bindings.bindContent(names, beans);
Button addChoiceBoxButton = new Button("Add ChoiceBox");
addChoiceBoxButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
ChoiceBox<BeanExample2> choiceBox = new ChoiceBox<BeanExample2>(names);
vBar.getChildren().add(choiceBox);
}
});
vBar.getChildren().add(addChoiceBoxButton);
return vBar;
}
static class BeanExample2 {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString() {
return "BeanExample2{" +
"name='" + name + '\'' +
'}';
}
}
}
Here
ObservableList<BeanExample2> names = FXCollections.observableArrayList(new Callback<BeanExample2, Observable[]>() {
#Override
public Observable[] call(BeanExample2 param) {
return new Observable[]{new SimpleStringProperty(param, "name")};
}
});
you're creating a new property to listen to for updates that cannot be referenced except from the value returned by the call method. The only relationship between the BeanExample2 instance and the SimpleStringProperty is that the BeanExample2 instance is used as bean for the property, which has no effect besides being available via the getBean() method of the property. The value of the property is never assigned let alone modified on a change of the BeanExample2 instance.
To properly trigger updates in the ObservableList, you need to make sure the element in the array returned by the above method is actually notified of updates. Usually you add the property to the class itself:
public static class BeanExample2 {
public final String getName() {
return this.name.get();
}
private final StringProperty name = new SimpleStringProperty();
public final void setName(String value) {
this.name.set(value);
}
#Override
public String toString() {
return "BeanExample2{"
+ "name='" + name.get() + '\''
+ '}';
}
public final StringProperty nameProperty() {
return this.name;
}
}
And return an array containing the property from the Callback
ObservableList<BeanExample2> names = FXCollections.observableArrayList(new Callback<BeanExample2, Observable[]>() {
#Override
public Observable[] call(BeanExample2 param) {
return new Observable[]{param.nameProperty()};
}
});
Note that currently there seems to be a bug in ChoiceBox that adds entries for every intermediate value to the ChoiceBox.
ComboBox does not have this issue and could be used instead of a ChoiceBox.

JavaFX: TableView row selection

I am working on a java/Javafx project for the first time and i have a TableView with multiple column (name, prename, age...) to present my data and I need the user to be able to select a single row and give me everytime all anformation about the person(Other columns) even when he click at another column but I haven't been able to find the right way to do it.
When i select a row my code give everytime the value of the cell i click on, but i need other informations to search with in my SQLite data base and work on it (Delete/edit this person..)
Here is the code that i use:
...//rest of code
#Override
public void initialize(URL location, ResourceBundle resources) {
private TableView<Student> tbl_elev=new TableView<Student>();
...
tbl_elev.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {
#Override
public void changed(ObservableValue<?> observableValue, Object oldValue, Object newValue) {
//Check whether item is selected and set value of selected item to Label
if (tbl_elev.getSelectionModel().getSelectedItem() != null) {
TableViewSelectionModel<Student> selectionModel = tbl_elev.getSelectionModel();
ObservableList<?> selectedCells = selectionModel.getSelectedCells();
#SuppressWarnings("unchecked")
TablePosition<Object, ?> tablePosition = (TablePosition<Object, ?>) selectedCells.get(0);
Object val = tablePosition.getTableColumn().getCellData(newValue);
System.out.println("Selected Value " + val);
}
}
});
}
... //rest of code
I am waiting for your suggestions and ideas, i dont mind if you suggest another approach because this may be uncompatible (taken from internet) Please if you need any other part of the code just comment, i don't put it all because it is too long to read.. (Sorry of my bad english)
If you specify that the ChangeListener parameters are of type Student you can get use the instance methods from that object:
Here's a Minimal, Complete, and Verifiable example:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class SSCCE extends Application {
#Override
public void start(Stage stage) {
VBox root = new VBox();
TableView<Student> studentsTable = new TableView<Student>();
HBox studentBox = new HBox();
Label studentHeader = new Label("Student: ");
Label studentInfo = new Label("");
studentBox.getChildren().addAll(studentHeader, studentInfo);
root.getChildren().addAll(studentsTable, studentBox);
// Prepare the columns
TableColumn<Student, String> firstNameCol = new TableColumn<Student, String>(
"First name");
firstNameCol.setCellValueFactory(cellData -> cellData.getValue()
.firstNameProperty());
TableColumn<Student, String> lastNameCol = new TableColumn<Student, String>(
"Last name");
lastNameCol.setCellValueFactory(cellData -> cellData.getValue()
.lastNameProperty());
studentsTable.getSelectionModel().selectedItemProperty()
.addListener(new ChangeListener<Student>() {
// Here's the key part. See how I specify that the
// parameters are of type student. Now you can use the
// instance methods from Student.
#Override
public void changed(
ObservableValue<? extends Student> observable,
Student oldValue, Student newValue ) {
studentInfo.setText(newValue.getFirstName() + " "
+ newValue.getLastName());
// If you want to get the value of a selected student cell at
// anytime, even if it hasn't changed. Just do e.g.
// studentsTable.getSelectionModel().getSelectedItem().getFirstName()
}
});
studentsTable.getColumns().setAll(firstNameCol, lastNameCol);
// Some mock Student objects
Student student1 = new Student("Eric", "Smith");
Student student2 = new Student("Brad", "Jones");
Student student3 = new Student("Logan", "Thorpe");
// Fill the table with students.
studentsTable.getItems().addAll(student1, student2, student3);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
// The student class. In this case an inner class to simplify the example. But generally you should never use inner classes.
class Student {
private StringProperty firstName;
private StringProperty lastName;
public Student(String firstName, String lastName) {
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String firstName) {
this.firstName.set(firstName);
}
public StringProperty firstNameProperty() {
return firstName;
}
public String getLastName() {
return lastName.get();
}
public void setLastName(String lastName) {
this.lastName.set(lastName);
}
public StringProperty lastNameProperty() {
return lastName;
}
}
}
After too many failed attempts and thanks to #Jonatan 's answer the code after i compelete some missing words should be like this:
...//rest of code
#Override
public void initialize(URL location, ResourceBundle resources) {
private TableView<Student> tbl_elev=new TableView<Student>();
...
tbl_elev.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Student>() {
// Here's the key part. See how I specify that the
// parameters are of type student. Now you can use the
// instance methods from Student.
#Override
public void changed(ObservableValue<? extends Student> observable,Student oldValue, Student newValue){
if(newValue!=null){
System.out.println(newValue.getName() + " "+ newValue.getPrename()+" "+newValue.getNaiss());
}
//you can add any other value from Student class via getter(getAdr,getMail,...)
}
});
}
... //rest of code
Output example:
Jonatan stenbacka 2015-09-11
Those value are ready for use to fetch the data base and specify the needed row in it to work on.
Hope that this help someone one day.
thanks...

Does PropertyValueFactory need valueProperty method in model or not?

I am trying to make a table with a TableView and fill it based on a list of Actors object. The Actor Model is bellow.
public class Actor {
private SimpleIntegerProperty actorId;
private SimpleStringProperty firstName;
private SimpleStringProperty lastName;
private SimpleStringProperty email;
public Actor(int id, String first, String last, String e){
actorId = new SimpleIntegerProperty(id);
firstName = new SimpleStringProperty(first);
lastName = new SimpleStringProperty(last);
email = new SimpleStringProperty(e);
}
public void setActorId(int id){
actorId.set(id);
}
public int getActorId(){
return actorId.get();
}
public void setFirstName(String name){
firstName.set(name);
}
public String getFirstName(){
return firstName.get();
}
public void setLastName(String last){
lastName.set(last);
}
public String getLastName(){
return lastName.get();
}
public void setEmail(String e){
email.set(e);
}
public String getEmail(){
return email.get();
}
}
And here is my TableVeiw class
public class SakilaApp extends Application {
private TableView<Actor> actorTable = new TableView<Actor>();
private final ObservableList<Actor> actorData = FXCollections.observableArrayList(
new Actor(1, "Mohsen","Parsa", "Mohseh.parsa313#gmail.com"),
new Actor(2, "Morteza","Ghasemi", "Morteza.Ghasemi#gmail.com"),
new Actor(3, "Mohammad","Fetrat", "Mohammad.Fetrat#gmail.com"),
new Actor(4, "Nader","AhmadYar", "Nader.AhmadYar#gmail.com" )
);
#SuppressWarnings("unchecked")
#Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(600);
stage.setHeight(500);
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
actorTable.setEditable(true);
TableColumn<Actor, Integer> idCol = new TableColumn<Actor, Integer>("Actor ID");
idCol.setCellValueFactory(
new PropertyValueFactory<Actor, Integer>("actorId"));
idCol.setPrefWidth(60);
TableColumn<Actor, String> firstNameCol = new TableColumn<Actor, String>("First Name");
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Actor, String>("firstName"));
firstNameCol.setPrefWidth(100);
TableColumn<Actor, String> lastNameCol = new TableColumn<Actor, String>("Last Name");
lastNameCol.setCellValueFactory(
new PropertyValueFactory<Actor, String>("lastName"));
lastNameCol.setPrefWidth(100);
TableColumn<Actor, String> emailCol = new TableColumn<Actor, String>("Email");
emailCol.setCellValueFactory(
new PropertyValueFactory<Actor, String>("email"));
emailCol.setPrefWidth(200);
TableColumn<Actor, String> lastUpdateCol = new TableColumn<Actor, String>("Last Update");
lastUpdateCol.setCellValueFactory(
new PropertyValueFactory<Actor, String>("lastUpdate"));
lastUpdateCol.setPrefWidth(100);
actorTable.getColumns().addAll(idCol, firstNameCol, lastNameCol, emailCol);
actorTable.setItems(actorData);
final VBox actorBox = new VBox();
actorBox.setSpacing(5);
actorBox.setPadding(new Insets(10, 0, 0, 10));
actorBox.getChildren().addAll(label, actorTable);
((Group) scene.getRoot()).getChildren().addAll(actorBox);
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
Application.launch(args);
}
}
My problem is that as they mentioned in this article
How to use the PropertyValueFactory correctly?
new PropertyValueFactory<Actor, Integer>("actorId")
will lookup for :
Actor.actorIdProperty()
but as you can see in Actor model there is no any methods with the name of
IntegerProperty actorIdProperty()
My question is, Do we need such method or not?
if it is necessary, why this code works correctly?
Depends on what you mean by "work" :-)
As long as the TableView is read-only, getters/setters are enough: data is shown as expected. As soon as the TableView is editable, the data won't be updated automatically. In the latter case, you'll have the option to either install a custom commit handler or expose the properties which will allow internal magic to work.
As you have them anyway, I see no reason not to (and not follow buggy example in the tutorial)
The JavaDoc of PropertyValueFactory states that you need a field called
SimpleIntegerProperty actorIdProperty;
so really I think you should.
However, looking at the code of PropertyValueFactory I notice that it falls back to a getter if the property field isn't available:
if (propertyRef.hasProperty()) {
return propertyRef.getProperty(rowData);
} else {
T value = propertyRef.get(rowData);
return new ReadOnlyObjectWrapper<T>(value);
}
so that is why your code works as is.
If I were you I would follow the JavaDoc and rename your field to actorIdProperty because you never know when they could change the implementation.

How to build TreeView from Arraylist

I'm looking for a solution how to build a JavaFX TreeView from an ArrayList. I have this ArrayList witch contains connection name, database server name and list of tables:
public List<ConnectionsListObj> connListObj = new ArrayList<>();
public class ConnectionsListObj {
private String connectionName;
private String dbgwName;
private String tableName;
public ConnectionsListObj(String connectionName, String dbgwName, String tableName) {
this.connectionName = connectionName;
this.dbgwName = dbgwName;
this.tableName = tableName;
}
public String getConnectionName() {
return connectionName;
}
public void setConnectionName(String connectionName) {
this.connectionName = connectionName;
}
public String getDbgwName() {
return dbgwName;
}
public void setDbgwName(String dbgwName) {
this.dbgwName = dbgwName;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
}
I need some kind of a loop which looks into the tree and generates tree using this code:
TreeItem<String> treeItemConnections = new TreeItem<> ("Connections");
TreeItem<String> nodeItemDBGW = new TreeItem<>("DBGW 1");
treeItemConnections.getChildren().add(nodeItemDBGW);
TreeItem<String> nodeItemTable = new TreeItem<>("Table 1");
nodeItemDBGW.getChildren().add(nodeItemTable);
TreeView<String> treeView = new TreeView<>(treeItemConnections);
StackPane root = new StackPane();
root.getChildren().add(treeView);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("java-buddy.blogspot.com");
primaryStage.setScene(scene);
primaryStage.show();
The question is how I can make a loop which looks into the ArrayList and constructs the three? And also when I select on a node I want to get the type of the node.
Why not just put the ConnectionsListObj objects in the tree? I think TreeView calls toString() on the objects for the text in each tree node so just return the string you want to show from ConnectionsListObj.toString(). Then when you get the selected item by calling myTreeView.getSelectionModel().getSelectedItems() you get an instance of ConnectionsListObj which should have all the data you need.
Loops in java look like the following for your case:
for(ConnectionsListObj connection : connListObj) {
nodeItemDBGW.getChildren().add(connection);
}
or...
nodeItemDBGW.getChildren().addAll(connListObj);

Categories

Resources