У меня есть программа, которая в основном является диспетчером задач, она берет информацию из базы данных SQLite.имеет 5 информационных полей (UID, Дата, CreatedBy, Категория, Задача).Для заполнения табличного представления я использую класс Model Table.
Контроллер
@FXML public TableView<ModelTable> taskManagerView;
@FXML public TableColumn<ModelTable, String> col_UID;
@FXML public TableColumn<ModelTable, String> col_Date;
@FXML public TableColumn<ModelTable, String> col_CreatedBy;
@FXML public TableColumn<ModelTable, String> col_Category;
@FXML public TableColumn<ModelTable, String> col_Task;
ObservableList<ModelTable> oblist = FXCollections.observableArrayList();
public FilteredList<ModelTable> filteredOblist = new FilteredList<>(oblist, s -> true);
try{
Connection conn =
DriverManager.getConnection("jdbc:sqlite://Location\\");
Statement statement = conn.createStatement();
ResultSet rs =statement.executeQuery("SELECT * FROM TaskManagerData");
while (rs.next()){
oblist.add(new ModelTable(rs.getString("UID"), rs.getString("Date"), rs.getString("CreatedBy"), rs.getString("Category"),rs.getString("Task")));
}
}catch (SQLException e){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("DB Error");
alert.setHeaderText("DB Connection Failed");
alert.setContentText(e.getMessage());
alert.showAndWait();
}
col_UID.setCellValueFactory(new PropertyValueFactory<>("UID"));
col_Date.setCellValueFactory(new PropertyValueFactory<>("Date"));
col_CreatedBy.setCellValueFactory(new PropertyValueFactory<>("CreatedBy"));
col_Category.setCellValueFactory(new PropertyValueFactory<>("Category"));
col_Task.setCellValueFactory(new PropertyValueFactory<>("Task"));
taskManagerView.setItems(filteredOblist);
ModelTable gettingTask =taskManagerView.getSelectionModel().getSelectedItem();
detailedTask.setText(gettingTask.getTask());
Model Table:
public class ModelTable {
String UID, Date, CreatedBy, Category, Task;
package Controllers;
public class ModelTable {
String UID, Date, CreatedBy, Category, Task;
public ModelTable(String UID, String date, String createdBy, String category, String task) {
this.UID = UID;
Date = date;
CreatedBy = createdBy;
Category = category;
Task = task;
}
public String getUID() {
return UID;
}
public void setUID(String UID) {
this.UID = UID;
}
public String getDate() {
return Date;
}
public void setDate(String date) {
Date = date;
}
public String getCreatedBy() {
return CreatedBy;
}
public void setCreatedBy(String createdBy) {
CreatedBy = createdBy;
}
public String getCategory() {
return Category;
}
public void setCategory(String category) {
Category = category;
}
public String getTask() {
return Task;
}
public void setTask(String task) {
Task = task;
}
}
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="488.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controllers.TaskManagerController">
<children>
<AnchorPane layoutY="3.0" prefHeight="165.0" prefWidth="600.0" AnchorPane.bottomAnchor="320.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="3.0">
<children>
<MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="600.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="2.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Add Entry" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<TextField fx:id="filter_uid" alignment="CENTER" layoutX="14.0" layoutY="62.0" promptText="UID" />
<TextField fx:id="filter_created" alignment="CENTER" layoutX="14.0" layoutY="98.0" promptText="Created By" />
<DatePicker fx:id="filter_date" layoutX="172.0" layoutY="98.0" onAction="#dateFilter" prefHeight="25.0" prefWidth="167.0" promptText="Date" />
<TextArea fx:id="detailedTask" editable="false" layoutX="348.0" layoutY="27.0" prefHeight="137.0" prefWidth="252.0" AnchorPane.leftAnchor="348.0" AnchorPane.rightAnchor="0.0" />
<RadioButton fx:id="radioHomework" layoutX="172.0" layoutY="79.0" mnemonicParsing="false" onAction="#radioButtonOne" text="Homework" />
<RadioButton fx:id="radioMaintenance" layoutX="172.0" layoutY="62.0" mnemonicParsing="false" onAction="#radioButtonTwo" text="Maintenance" />
<RadioButton fx:id="radioOther" layoutX="262.0" layoutY="62.0" mnemonicParsing="false" onAction="#radioButtonThree" text="Other" />
<RadioButton fx:id="radioNull" layoutX="262.0" layoutY="79.0" mnemonicParsing="false" onAction="#radioButtonFour" text="Show All" />
<Label layoutX="14.0" layoutY="39.0" prefHeight="17.0" prefWidth="326.0" style="-fx-alignment: CENTER;" text="FILTERS" textAlignment="CENTER">
<font>
<Font size="15.0" />
</font>
</Label>
</children></AnchorPane>
<TableView fx:id="taskManagerView" layoutY="166.0" prefHeight="282.0" prefWidth="600.0" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="166.0">
<columns>
<TableColumn fx:id="col_UID" prefWidth="70.0" text="UID" />
<TableColumn fx:id="col_Date" prefWidth="100.0" text="Date" />
<TableColumn fx:id="col_CreatedBy" prefWidth="90.0" text="Created By" />
<TableColumn fx:id="col_Category" prefWidth="100.0" text="Category" />
<TableColumn fx:id="col_Task" prefWidth="239.0" text="Task" />
</columns>
</TableView>
<ButtonBar layoutY="360.0" prefHeight="40.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<buttons>
<Button fx:id="addTask" mnemonicParsing="false" onAction="#addTaskFunction" text="Add Task" />
<Button fx:id="exportBtn" mnemonicParsing="false" onAction="#export" text="Export" />
<Button fx:id="backToMainMenu" mnemonicParsing="false" onAction="#backButton" text="Back" />
</buttons>
</ButtonBar>
</children>
</AnchorPane>
У меня вопрос: как мне это сделать, чтобы моя программа, когда я выбираю, например, UID 7 (когда программа запущена) из представления таблицы, информация из «Задачи» появляется в текстовой области программы.В настоящее время
Надеюсь, это было понятно.
Спасибо.