Я загрузил CSV-файл в табличное представление в javafx и пытаюсь найти в таблице свойства по номерам счетов, адресам, окрестностям и т. Д. c. Каждое текстовое поле соответствует определенной цели поиска c, а также раскрывающемуся селектору. В моем стремлении решить эту проблему все примеры я нашел фильтр активно, где, как я нашел, нравится делать это, когда нажата кнопка поиска. Есть ли правильный способ отображать только искомые элементы в таблице и отображать информацию в текстовой области?
Контроллер таблицы:
public class FileGUI extends Application {
TableView table;
ObservableList<PropertyData> data;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Property Assesments");
// For Label + table
// placed vertically (above one another)
VBox vb1 = new VBox(20); // set spacing between these nodes to 10
// For Label + text field
// placed vertically (above one another)
VBox vb2 = new VBox(20); // set spacing between these nodes to 5
// vb1 and vb2 will be placed horizontally
HBox hb = new HBox(150); // set spacing between vb1 and vb2 to 20
// set the scene
Scene scene = new Scene(hb, 1000, 1000);
//Set Text Labels
Label label1 = new Label("Property Data");
label1.setFont(new Font("Ariel",15));
createSimpleTable();
vb1.setAlignment(Pos.CENTER_LEFT);
vb1.getChildren().addAll(label1,table);
Label label2 = new Label("Find Property Assesment");
label2.setFont(new Font("Ariel", 15));
label2.setStyle("-fx-font-weight: bold;");
Label label3 = new Label("Account Number:");
label3.setFont(Font.font("Ariel", FontWeight.NORMAL, 12));
label3.setPadding(new Insets(10, 0, 0, 0));
TextField tf = new TextField();
Label label4 = new Label("Address (#suite #house street):");
label4.setFont(Font.font("Ariel", FontWeight.NORMAL, 12));
TextField tf2 = new TextField();
Label label5 = new Label("Neighbourhood:");
label5.setFont(Font.font("Ariel", FontWeight.NORMAL, 12));
TextField tf3 = new TextField();
Label label6 = new Label("Assessment Class:");
label6.setFont(Font.font("Ariel", FontWeight.NORMAL, 12));
//Set dropdown menu selection
MenuButton menuBtn = new MenuButton();
menuBtn.setPadding(new Insets(0, 0, 0, 100));
menuBtn.getItems().setAll(new MenuItem("Residential"), new MenuItem("Non Residential"), new MenuItem("Other Residential"));
Button search = new Button("Search");
Button reset = new Button("Reset");
reset.setTranslateX(70);
reset.setTranslateY(-37);
TextArea box = new TextArea();
box.setPadding(new Insets(0, 0, 0, 60));
vb2.setAlignment(Pos.CENTER_LEFT);
vb2.setSpacing(10);
vb2.setPadding(new Insets(13, 0, 0, 6));
vb2.getChildren().addAll(label2, label3, tf, label4, tf2, label5, tf3, label6, menuBtn, search, reset, box);
EventHandler<ActionEvent> searchAcc = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String accNumber = tf.getText();
}
};
hb.setAlignment(Pos.BASELINE_LEFT);
hb.getChildren().addAll(vb2, vb1);
primaryStage.setScene(scene);
primaryStage.show();
}
public void createSimpleTable() {
table = new TableView();
//Open file as class object
InitFile csvFile = new InitFile();
//Check if pathway provided by user exists, if not return default pathway
File pathName = csvFile.FileExists();
try {
//Read file line by line until EOF into Property data structure array
ArrayList<PropertyData> houses = csvFile.initializeFile(pathName);
data = FXCollections.observableArrayList(houses);
TableColumn acc = new TableColumn("Account");
acc.setMinWidth(90);
acc.setCellValueFactory(new PropertyValueFactory("accountNum"));
TableColumn add = new TableColumn("Address");
add.setMinWidth(180);
add.setCellValueFactory(new PropertyValueFactory("houseNum"));
add.setCellValueFactory(new PropertyValueFactory("suite"));
add.setCellValueFactory(new PropertyValueFactory("streetName"));
TableColumn assessedVal = new TableColumn("Assessed Value");
assessedVal.setMinWidth(120);
assessedVal.setCellValueFactory(new PropertyValueFactory("assessedVal"));
TableColumn assessClass = new TableColumn("Assessment Class");
assessClass.setMinWidth(120);
assessClass.setCellValueFactory(new PropertyValueFactory("assessClass"));
TableColumn nh = new TableColumn("Neighbourhood");
nh.setMinWidth(190);
nh.setCellValueFactory(new PropertyValueFactory("neighbourhood"));
TableColumn lat = new TableColumn("Latitude");
lat.setMinWidth(130);
lat.setCellValueFactory(new PropertyValueFactory("latitude"));
TableColumn lng = new TableColumn("Longitude");
lng.setMinWidth(130);
lng.setCellValueFactory(new PropertyValueFactory("longitude"));
table.setEditable(false);
table.setPrefWidth(920);
table.setPrefHeight(640);
table.getColumns().addAll(acc, add, assessedVal, assessClass, nh, lat, lng);
table.setItems(data);
} catch (Exception e) {
System.out.println("File not Found");
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Изображение GUI