The TableView has a built-in scroll bar, but why do I not see the vertical scroll bar?
Here is my code when I put TableView in a HBox:
HBox HBox_tabelDatabase = new HBox();
HBox_tabelDatabase.setAlignment(Pos.TOP_CENTER);
HBox_tabelDatabase.setPadding(new Insets(5,5,5,5));
HBox_tabelDatabase.setStyle( "-fx-border-style: solid;"
+ "-fx-border-width: 1;"
+ "-fx-border-color: #ADDFFF;"
+ "-fx-accent: #ADDFFF;"
+ "-fx-accent: #ADDFFF;"
+ "-fx-base: #ADDFFF;"
+ "-fx-background: white;"
+ "-fx-control-inner-background: white;"
+ "-fx-focus-color: #ADDFFF;"
+ "-fx-dark-text-color: deepskyblue;"
+ "-fx-mid-text-color: black;"
+ "-fx-light-text-color: blue;");
Tab tab6 = new Tab();
HBox_tabelDatabase.getChildren().add(tableview);
HBox_tabelDatabase.setPrefHeight(200);
tab6.setText("Tabel Database");
tab6.setContent(HBox_tabelDatabase);
Here is my code to define TableView and its columns and rows:
private void buildData(){
Connection c ;
data = FXCollections.observableArrayList();
try{
c = DBConnect.connect();
//SQL FOR SELECTING ALL OF APP.tabelJembatan
String SQL = "SELECT * from APP.tabelJembatan";
//ResultSet
ResultSet rs = c.createStatement().executeQuery(SQL);
/**********************************
* TABLE COLUMN ADDED DYNAMICALLY *
**********************************/
for(int i=0 ; i<rs.getMetaData().getColumnCount(); i++){
//We are using non property style for making dynamic table
final int j = i;
TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i+1));
col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
public ObservableValue<String> call(TableColumn.CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
});
tableview.getColumns().addAll(col);
col.setMinWidth(200);
System.out.println("Column ["+i+"] ");
}
/********************************
* Data added to ObservableList *
********************************/
while(rs.next()){
//Iterate Row
ObservableList<String> row = FXCollections.observableArrayList();
for(int i=1 ; i<=rs.getMetaData().getColumnCount(); i++){
//Iterate Column
row.add(rs.getString(i));
}
System.out.println("Row [1] added "+row );
data.add(row);
}
//FINALLY ADDED TO TableView
tableview.setItems(data);
}catch(Exception e){
e.printStackTrace();
System.out.println("Error on Building Data");
}
Image for : The Vertical scroll bar on TableView is not Visible
and then, i try this to put the TableView into a ScrollPane, but the header is also moving when I’m scrolling data vertically. I mean, the header didn’t stay in that position. I used this code:
ScrollPane scrollpane1 = new ScrollPane();
scrollpane1.setContent(tableview);
Image for : The Header is also moving when I scrolled vertically
Is there any way to make the first row (Header) stay in that position when I am scrolling vertically?