2

I have a DB log in form on a single row as below,

    // Hostname Input
    Label hostName = new Label("Host:");
    grid.add(hostName, 0, 2);
    
    final TextField host = new TextField();
    host.getText();
    GridPane.setConstraints(host, 1, 2);
    grid.getChildren().add(host);
    
    // Port Input
    Label portName = new Label("Port:");
    grid.add(portName, 2, 2);

    final TextField port = new TextField();
    port.getText();
    GridPane.setConstraints(port, 3, 2);
    grid.getChildren().add(port);
    
    // SID Input
    Label sidName = new Label("SID:");
    grid.add(sidName, 4, 2);
    
    final TextField sid = new TextField();
    sid.getText();
    GridPane.setConstraints(sid, 5, 2);
    grid.getChildren().add(sid);
    
    // Username Input
    Label userName = new Label("Username:");
    grid.add(userName, 6, 2);
    
    final TextField user = new TextField();
    user.getText();
    GridPane.setConstraints(user, 7, 2);
    grid.getChildren().add(user);
    
    // Password Input
    Label pw = new Label("Password:");
    grid.add(pw, 8, 2);
    
    final TextField password = new PasswordField();
    password.getText();
    GridPane.setConstraints(password, 9, 2);
    grid.getChildren().add(password);

and I need to add more rows in the following case:

  1. When the txt input file has more than one line.

    ex) When there's one line, no need to extend, when two, need to add one more row.

  2. When the user click on the button to add the row.

Is it possible to do it in Java FX? Please help!!

Thank you for looking!

Community
  • 1
  • 1
Keibee
  • 45
  • 1
  • 5
  • Why don't you use a ListView or a TableView? – Roland Mar 11 '15 at 01:51
  • There is a custom control in [ContolsFX](http://controlsfx.bitbucket.org/org/controlsfx/control/PropertySheet.html) which possibly already does what you want – Inge Mar 11 '15 at 05:18

1 Answers1

1

Why don't you just use gridPane.addRow() when you are reading your textfile?

try(BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();
    int lineCounter = 0;

    while (line != null) {
        lineCounter++;
        if(lineCounter > 1){
            gridPane.addRow(lineCounter-1, nodeThatYouWant);
        }
        sb.append(line);
        sb.append(System.lineSeparator());
        line = br.readLine();
    }
    String everything = sb.toString();
}
Juce
  • 341
  • 1
  • 8
  • Using array solved the first issue I had. I will try to use this method for 2nd issue. Thanks! – Keibee Mar 17 '15 at 21:24
  • It's almost any JavaFX component https://www.google.es/search?q=javafx+node&ie=utf-8&oe=utf-8&client=firefox-b-ab&gfe_rd=cr&dcr=0&ei=A1hoWq6eNO_-8Afw3I7wBQ – MissingSemiColon Jan 24 '18 at 09:57