javafx fill tableview with data
Java
import java.sql.Connection;
import java.sql.ResultSet;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import javafx.util.Callback;
/**
*
* @author Narayan
*/
public class DynamicTable extends Application{
//TABLE VIEW AND DATA
private ObservableList<ObservableList> data;
private TableView tableview;
//MAIN EXECUTOR
public static void main(String[] args) {
launch(args);
}
//CONNECTION DATABASE
public void buildData(){
Connection c ;
data = FXCollections.observableArrayList();
try{
c = DBConnect.connect();
//SQL FOR SELECTING ALL OF CUSTOMER
String SQL = "SELECT * from CUSTOMer";
//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<CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
});
tableview.getColumns().addAll(col);
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");
}
}
@Override
public void start(Stage stage) throws Exception {
//TableView
tableview = new TableView();
buildData();
//Main Scene
Scene scene = new Scene(tableview);
stage.setScene(scene);
stage.show();
}
}
Also in Java:
- Title
- set view layout params android
- Category
- Java
- Title
- hashset contains java
- Category
- Java
- Title
- how to find complement of a number in java
- Category
- Java
- Title
- array in java stack overflow
- Category
- Java
- Title
- iterate over map keys java
- Category
- Java
- Title
- java string split underscore
- Category
- Java
- Title
- download spring
- Category
- Java
- Title
- how to iterate hashmap in java
- Category
- Java
- Title
- java string indexof
- Category
- Java
- Title
- loop collection android
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- how to byheart faster
- Category
- Java
- Title
- springBoot
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- java execute jar from main
- Category
- Java
- Title
- how to add strings in java
- Category
- Java
- Title
- spigot title
- Category
- Java
- Title
- split method in java
- Category
- Java
- Title
- sdkmanager JAVA_HOME invalid directory
- Category
- Java
- Title
- create object of static class in java
- Category
- Java
- Title
- how to print ascii value in java
- Category
- Java
- Title
- java hashmap put
- Category
- Java
- Title
- testing the web layer without authentication spring
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- java split string on two or more spaces except for words in quotes
- Category
- Java
- Title
- java stream sort
- Category
- Java
- Title
- get random number from enum in java
- Category
- Java
- Title
- java print syntax
- Category
- Java
- Title
- goodbye java
- Category
- Java
- Title
- how do you concatenate an int with a string in java
- Category
- Java
- Title
- multiple string java
- Category
- Java
- Title
- what is graphics default color java
- Category
- Java
- Title
- arraylist remove method java
- Category
- Java
- Title
- changing double space to single in java script
- Category
- Java
- Title
- how to skip a line in java
- Category
- Java
- Title
- java "->"
- Category
- Java
- Title
- java setroundingmode
- Category
- Java
- Title
- write an object java in a file
- Category
- Java
- Title
- java remove double spaces
- Category
- Java
- Title
- compareto method java
- Category
- Java
- Title
- run static method java
- Category
- Java
- Title
- init admob
- Category
- Java
- Title
- java string to uuid
- Category
- Java
- Title
- java 8 group a collections by 2 property
- Category
- Java
- Title
- how to make a text field required in android studio
- Category
- Java
- Title
- java read lines from file
- Category
- Java
- Title
- java random numbers in specific range
- Category
- Java
- Title
- jbutton open jframe java
- Category
- Java
- Title
- calculate days between two dates in java
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- how to change double to int in java
- Category
- Java
- Title
- java sort method
- Category
- Java
- Title
- action on long press of edit edittext
- Category
- Java
- Title
- comparable on a generic class java
- Category
- Java
- Title
- keep jframe on top
- Category
- Java
- Title
- date format in java
- Category
- Java
- Title
- nth prime number java
- Category
- Java
- Title
- isSelfDivisor java
- Category
- Java
- Title
- initialize arraylist
- Category
- Java
- Title
- how to create a circle in java
- Category
- Java
- Title
- java list contains object with property
- Category
- Java
- Title
- how to print hello world in java
- Category
- Java
- Title
- get world by name bukkit
- Category
- Java
- Title
- Don't use a line-beased input after a token-based input.
- Category
- Java
- Title
- is self divisor java
- Category
- Java
- Title
- LocalRegistry java rebind() java8
- Category
- Java
- Title
- how to know when user is done typing android
- Category
- Java
- Title
- nullpointer extension
- Category
- Java
- Title
- java find biggest number in array
- Category
- Java
- Title
- count word in string no matter the delimiter java
- Category
- Java
- Title
- java pass array as method parameter
- Category
- Java
- Title
- get last element of array java
- Category
- Java
- Title
- java break in foreach
- Category
- Java
- Title
- android dynamically create layer-list with item and shape site:stackoverflow.com
- Category
- Java
- Title
- discord jda remove @everyone from channel
- Category
- Java
- Title
- remove last character from string java
- Category
- Java
- Title
- how get started with LWJGL 3
- Category
- Java
- Title
- capcitor FERR_CLEARTEXT_NOT_PERMITTED
- Category
- Java
- Title
- trees in java
- Category
- Java
- Title
- not equal java
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- How to draw Bezier Curve in Android
- Category
- Java
- Title
- how to count an replace string in java
- Category
- Java
- Title
- string to arraylist convert java
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- absolute value java
- Category
- Java
- Title
- how to make one java class inherit from another
- Category
- Java
- Title
- java create map
- Category
- Java
- Title
- Enums injava
- Category
- Java
- Title
- java string format with placeholder
- Category
- Java
- Title
- android java how to stop users fromgoing back too much
- Category
- Java
- Title
- stack class in java
- Category
- Java
- Title
- spigot spawn entity
- Category
- Java
- Title
- @JsonSerializer spring specific field string to date
- Category
- Java
- Title
- java cast duration to long
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- what is java plug-in
- Category
- Java
- Title
- javafx textarea how to make smaller
- Category
- Java
- Title
- java function without return
- Category
- Java
- Title
- python to java converter
- Category
- Java