-2

here is Consing.javahere is my table

This is my code.

public class TableViewByColumn extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
    ArrayList<Integer> intValues = Consing.getInstance().getBook_ID();
    ArrayList<String> stringValues = Consing.getInstance().getBookName();

    TableView<Integer> table = new TableView<>();
    for(int i=0; i<intValues.size()& i<stringValues.size(); i++){
        table.getItems().add(i);
    }

    TableColumn<Integer,String> stringColunm = new TableColumn<>("Name");
    stringColunm.setCellValueFactory(cellData -> {
        Integer rowIndex = cellData.getValue();
        System.out.println(rowIndex);
        return new ReadOnlyStringWrapper(stringValues.get(rowIndex));
    });

    TableColumn<Integer,Number> intColunm = new TableColumn<>("Value");
    intColunm.setCellValueFactory(cellData -> {
        Integer rowIndex = cellData.getValue();
        return new ReadOnlyIntegerWrapper(intValues.get(rowIndex));
    });
    table.getColumns().add(intColunm);
    table.getColumns().add(stringColunm);
    primaryStage.setScene(new Scene(new BorderPane(table),600,600));
    primaryStage.show();
}

here is my result

book_ids and names are not equal as from table.

1 Answers1

-1

how are you fetching the data from your MySQL database? It looks like you are fetching bookID and bookName separately, is that correct? If you do that, there is no ordering guarantee so intValues[0] does not necessary have to match with stringValues[0].

  • This does not answer the question; please ask for clarification by adding a comment to the question itself. – Zephyr Jun 18 '18 at 12:38