javafx - Creating rows after creating custom columns -


i creating scoreboard javafx.
program has table, 1 column game id. when press new game can add 10 players. type in players names , press button add players table columns. have provided pics below can have clearer understanding.

adding players

after players added columns

here i'm stuck. need add scores per game on rows. since i'm generating custom number (2-10) of columns depending on number of players. can't use code because don't know how many parameter needed score constructor in score class.

is there way create 3 int parameter in score class if there 3 players added? or approach in different way? option maybe add random numbers below dynamically editing rows real score, again program doesn't know how many columns there hard well.

public observablelist<score> getscore() {         observablelist<score> scores= fxcollections.observablearraylist();         scores.add(new score(10,12,13,11,15,90));         scores.add(new score(100,10,29,29));         return scores;     }  

example of i'm think how should look:

game nr:|bill gates | steve jobs |    1    |    80     |    10      |    2    |    6      |    75      | 

ps: there way sum column , show total score. want sum on last row if add new row scores sum appear below row.

codes used add players textfield column:

        tablecolumn<player, string> p1 = new tablecolumn<>(player1.gettext());         tablecolumn<player, string> p2 = new tablecolumn<>(player2.gettext());         tablecolumn<player, string> p3 = new tablecolumn<>(player3.gettext());         table.getcolumns().addall(p1, p2, p3); 

you can create game class has game number (fixed) , represents scores map players values:

public class game {     private final int gamenumber ;     private final observablemap<string, integer> scores          = fxcollections.observablehashmap();      public game(int gamenumber) {         this.gamenumber = gamenumber ;     }      public observablemap<string, integer> getscores() {         return scores ;     }      public int getgamenumber() {         return gamenumber ;     } } 

if understand requirements correctly, when user enters new players, want reset table, can method below:

private tableview<game> scoretable ;  // ...  private void resettable(list<string> players) {     scoretable.getcolumns().clear();     scoretable.getitems().clear();      tablecolumn<game, integer> gamenumcol = new tablecolumn<>("game");     gamenumcol.setcellvaluefactory(celldata -> new observablevaluebase<integer>() {         @override         public integer getvalue() {             return celldata.getvalue().getgamenumber();         }     });     scoretable.getcolumns().add(gamenumcol);      (string player : players) {         tablecolumn<game, integer> col = new tablecolumn<>(player);         col.setcellvaluefactory(celldata -> {             game game = celldata.getvalue();             integerbinding score = bindings.createintegerbinding(() ->                game.getscores().getordefault(player, 0),                game.getscores());             return score.asobject() ;         });         // if need editing:         col.setoneditcommit(e -> {             game game = e.getrowvalue();             integer newscore = e.getnewvalue();             game.getscores().put(player, newscore);         });         scoretable.getcolumns().add(col);     } } 

then can add new games table's items list, , default 0 scores each player. can set scores with

game.getscores().put(player, score); 

sscce @ https://gist.github.com/james-d/aa51204a2e7ed16d75b7


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -