Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaFX architecture in building dynamic "rows"
    text
    copied!<p>I have an application that I am building that has a table in it, I'm not using a tableview to build this table because I need each row to be able to expand similar to an accordion. I was able to achieve what I need by using a timeline and looping through the data and building each row (its kind of crude right now since I'm still working with dummy data eventually it will be a list iterator and not just a for loop) but I'm not happy with how its done. There are a lot of default values that will never change so I don't really need to set them in my worker class every time, I decided to just add them to the object class that I put together. So basically, at a high level it looks something like this:</p> <pre><code>for (int i = 0; i &lt; 30; i++) { RowBuilder builder = new RowBuilder(tableBox, i); try { builder.run(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } </code></pre> <p>I'm passing it the parent which is a VBox - tableBox, then I'm passing the count for later use. </p> <p>Inside the RowBuilder I'm getting a new instance of the object DashboardRow which has all the defaults set in it, then I'm setting the data for each row and returning the DashboardRow. </p> <p>Here is an example of a getter setting values in the DashboardRow</p> <pre><code>public HBox getMainRow() { mainRow.setAlignment(Pos.CENTER_LEFT); mainRow.setPrefHeight(60); mainRow.setMinHeight(60); mainRow.setMaxHeight(60); mainRow.setPrefWidth(-1); mainRow.setStyle("-fx-background-color:#FFFFFF;"); return mainRow; } </code></pre> <p>Inside the DashboardRow class I have a ton of new objects being created for every element I need in the row. There are 21 for each row, mostly VBox, HBox and StackPane to build the actual row, the rest are just labels and buttons.</p> <p>This is what is looks like so far. Opened and closed states.</p> <p><img src="https://dl.dropboxusercontent.com/u/5585458/Screenshot%202013-11-25%2011.36.58.png" /><br /> Is there a better way to dynamically build things like this in javafx? I'm basically pulling data from a database and looping through that data to populate a row. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload