forked from AlexTheaker04/DCSS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
151 lines (112 loc) · 4.32 KB
/
Test.java
File metadata and controls
151 lines (112 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package application;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Test extends Application {
public class Record {
//Assume each record have 6 elements, all String
private SimpleStringProperty f1, f2, f3, f4, f5, f6;
public String getF1() {
return f1.get();
}
public String getF2() {
return f2.get();
}
public String getF3() {
return f3.get();
}
public String getF4() {
return f4.get();
}
public String getF5() {
return f5.get();
}
public String getF6() {
return f6.get();
}
Record(String f1, String f2, String f3, String f4,
String f5, String f6) {
this.f1 = new SimpleStringProperty(f1);
this.f2 = new SimpleStringProperty(f2);
this.f3 = new SimpleStringProperty(f3);
this.f4 = new SimpleStringProperty(f4);
this.f5 = new SimpleStringProperty(f5);
this.f6 = new SimpleStringProperty(f6);
}
}
private final TableView<Record> tableView = new TableView<>();
private final ObservableList<Record> dataList
= FXCollections.observableArrayList();
@SuppressWarnings("rawtypes")
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("CVS");
Group root = new Group();
TableColumn columnF1 = new TableColumn("f1");
columnF1.setCellValueFactory(
new PropertyValueFactory<>("f1"));
TableColumn columnF2 = new TableColumn("f2");
columnF2.setCellValueFactory(
new PropertyValueFactory<>("f2"));
TableColumn columnF3 = new TableColumn("f3");
columnF3.setCellValueFactory(
new PropertyValueFactory<>("f3"));
TableColumn columnF4 = new TableColumn("f4");
columnF4.setCellValueFactory(
new PropertyValueFactory<>("f4"));
TableColumn columnF5 = new TableColumn("f5");
columnF5.setCellValueFactory(
new PropertyValueFactory<>("f5"));
TableColumn columnF6 = new TableColumn("f6");
columnF6.setCellValueFactory(
new PropertyValueFactory<>("f6"));
tableView.setItems(dataList);
tableView.getColumns().addAll(
columnF1, columnF2, columnF3, columnF4, columnF5, columnF6);
VBox vBox = new VBox();
vBox.setSpacing(10);
vBox.getChildren().add(tableView);
root.getChildren().add(vBox);
primaryStage.setScene(new Scene(root, 700, 250));
primaryStage.show();
readCSV();
}
private void readCSV() {
String CsvFile = "C:\\Users\\andre\\Desktop\\testCsv.csv";
String FieldDelimiter = ",";
BufferedReader br;
try {
br = new BufferedReader(new FileReader(CsvFile));
String line;
while ((line = br.readLine()) != null) {
String[] fields = line.split(FieldDelimiter, -1);
Record record = new Record(fields[0], fields[1], fields[2],
fields[3], fields[4], fields[5]);
dataList.add(record);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Test.class.getName())
.log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Test.class.getName())
.log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
launch(args);
}
}