Mysql 新窗口中的搜索结果(JavaFx)

Mysql 新窗口中的搜索结果(JavaFx),mysql,javafx,tableview,textfield,Mysql,Javafx,Tableview,Textfield,我目前正在开发一个软件模块,包括使用JavaFx在数据库中搜索。 一切正常。 但唯一的问题是,在我的结果表中,我只显示了很少的搜索细节(来自UX问题:我有太多的细节和长文本)。 我想做的是显示一个新窗口,其中包含TextFields和TextArea中单击行的所有详细信息。 我看了几个教程和答案,但不幸的是,没有什么是有效的。 任何帮助都将不胜感激! 多谢各位 SearchResult.setOnMouseClicked(new EventHandler<MouseEvent>()

我目前正在开发一个软件模块,包括使用JavaFx在数据库中搜索。 一切正常。 但唯一的问题是,在我的结果表中,我只显示了很少的搜索细节(来自UX问题:我有太多的细节和长文本)。 我想做的是显示一个新窗口,其中包含TextFields和TextArea中单击行的所有详细信息。 我看了几个教程和答案,但不幸的是,没有什么是有效的。 任何帮助都将不胜感激! 多谢各位

SearchResult.setOnMouseClicked(new EventHandler<MouseEvent>() {
        Gemo temp;
        @Override
        public void handle(MouseEvent event) {
            Gemo row = SearchResult.getSelectionModel().getSelectedItem();
            if(row == null) {
                System.out.print("I am not in");
                return ;
            }
            else {
                temp = row;

                String id = String.format(temp.getRef());
                System.out.println(id);
                FXMLLoader loader=new FXMLLoader();
                loader.setLocation(getClass().getResource("DetailsWindow.fxml"));
                ControllerDetails gemodetails=loader.getController();
                ControllerDetails gd=new ControllerDetails();
                gd.SearchById(id);
                try{
                    loader.load();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Parent p= loader.getRoot();
                Stage stage=new Stage();
                stage.setTitle("More Details");
                stage.setScene(new Scene(p));
                stage.show();




            }


        }
    });




public class ControllerDetails {
    @FXML
    private TextField fn_patient;

    @FXML
    private TextField ln_patient;

    @FXML
    private TextField db_patient;

    @FXML
    private TextField id_patient;

    @FXML
    private TextField id_visit;

    @FXML
    private TextField date_visit;

    @FXML
    private TextField fn_user;

    @FXML
    private TextField ln_user;

    @FXML
    private TextField status;
    @FXML
    private TextArea com;

    @FXML
    public void initialize(){

    }

    public void SearchById(String id) {
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet rs = null;
        try {

            connection = ConnectionConfiguration.getConnection();
            statement = connection.prepareStatement("my_sql_query");
            rs = statement.executeQuery();
            while (rs.next()) {


                id_visit.setText(rs.getString(1));
                id_patient.setText(rs.getString(2));
                date_visit.setText(rs.getString(3));
                com.setText(rs.getString(4));
                fn_patient.setText(rs.getString(5));
                ln_patient.setText(rs.getString(6));
                db_patient.setText(rs.getString(7));
                fn_user.setText(rs.getString(8));
                ln_user.setText(rs.getString(9));
                status.setText(rs.getString(10));



              }
          } catch (SQLException e) {
             e.printStackTrace();
        }
     }
 }
SearchResult.setOnMouseClicked(新的EventHandler(){
Gemo温度;
@凌驾
公共无效句柄(MouseeEvent事件){
Gemo row=SearchResult.getSelectionModel().getSelectedItem();
if(行==null){
系统输出打印(“我不在”);
返回;
}
否则{
温度=行;
String id=String.format(temp.getRef());
系统输出打印项次(id);
FXMLLoader=新的FXMLLoader();
setLocation(getClass().getResource(“DetailsWindow.fxml”);
ControllerDetails gemodetails=loader.getController();
ControllerDetails gd=新的ControllerDetails();
gd.SearchById(id);
试一试{
loader.load();
}捕获(IOE异常){
e、 printStackTrace();
}
父p=loader.getRoot();
阶段=新阶段();
舞台。片名(“更多细节”);
舞台场景(新场景(p));
stage.show();
}
}
});
公共类控制器详细信息{
@FXML
私人TextField fn_患者;
@FXML
私用文本字段ln_患者;
@FXML
私人文本字段db_患者;
@FXML
私人TextField id_患者;
@FXML
私人TextField id_访问;
@FXML
私人文本字段日期\访问;
@FXML
私有文本字段fn_用户;
@FXML
私有文本字段ln_用户;
@FXML
私有文本字段状态;
@FXML
私人短信区;
@FXML
公共无效初始化(){
}
公共无效SearchById(字符串id){
连接=空;
PreparedStatement=null;
结果集rs=null;
试一试{
connection=ConnectionConfiguration.getConnection();
语句=connection.prepareStatement(“我的sql查询”);
rs=语句。executeQuery();
while(rs.next()){
id_visit.setText(rs.getString(1));
id_patient.setText(rs.getString(2));
date_visit.setText(rs.getString(3));
setText(rs.getString(4));
fn_patient.setText(rs.getString(5));
ln_patient.setText(rs.getString(6));
db_patient.setText(rs.getString(7));
fn_user.setText(rs.getString(8));
ln_user.setText(rs.getString(9));
status.setText(rs.getString(10));
}
}捕获(SQLE异常){
e、 printStackTrace();
}
}
}

尝试使用listView创建一个简单的fxml文件。将您感兴趣的数据放入此listView。如果您喜欢listView以外的内容,也可以。 要在新窗口中打开此类fxml,请尝试以下操作:

Stage s = new Stage();
try {
    s.setScene(new Scene(new FXMLLoader(getClass().getResource("your_fxml_name")).load()));
    s.show();
} catch (IOException e) {
    e.printStackTrace();
}

您有两个操作选项:提取所有数据并将其粘贴到表中,或者提取放入表中的一小部分,然后根据需要提取额外的数据(显示详细信息)

我给出的示例并不沉迷于这种方法——它只是告诉我们如何将表数据(选定的行)传输到对话框(其控制器)

公共类控制器{
@FXML
私有TableView TableView;
@FXML
私有void初始化(){
setItems(新数据库().serach(“查询”,“查询”));
tableView.setOnMouseClicked(事件->{
if(event.getClickCount()==2){
showDetailsDialog();
}
});
}
私有void showDetails对话框(){
MySearchResult result=tableView.getSelectionModel().getSelectedItem();
如果(结果==null){
返回;
}
试一试{
FXMLLoader=newFXMLLoader(getClass().getResource(“details_dilaog.fxml”);
Dialog dlg=新建Dialog();
dlg.initOwner(tableView.getScene().getWindow());
dlg.initmodel(model.APPLICATION_model);
dlg.getDialogPane().setContent((父)loader.load());
dlg.getDialogPane().getButtonTypes().setAll(ButtonType.OK);
detailsDialogControllerDDC=loader.getController();
ddc.显示(结果)的详细信息;
dlg.showAndWait();
}
捕获(IOE异常){
e、 printStackTrace();
}
}
}

我的目标是在
showtailsdialog()
函数中显示逻辑。

您需要在问题中投入更多精力。展示您迄今为止所做的工作、日志、代码等。为什么不使用中描述的技术之一?我做了,但这不是我真正的问题。我只是想知道他们是否是从一个表中获取数据的一种方法,在这个表中,从数据库中提取的数据很少,可以在另一个窗口中以完整的格式显示所有数据data@GoSoft不清楚是什么阻止了你这么做。实际上,它与我所做的是一致的,只是我提取了一次访问的ID,并调用了第二个控制器的函数使用此ID作为参数。当我双击该行时,一切都进行得很顺利,并且得到了我的窗口,但是我的文本字段没有被数据库中的数据填充。我真的不明白为什么。@GoSoft,因为你没有调用
SearchById
。此外,您不能正确使用对话框控制器。仔细回顾我的例子中的动作顺序。谢谢你的快速回答,我想
public class Controller {

    @FXML
    private TableView<MySearchResult> tableView;

    @FXML
    private void initialize() {
        tableView.setItems(new Database().serach("query", "query"));

        tableView.setOnMouseClicked(event -> {
            if(event.getClickCount() == 2) {
                showDetailsDialog();
            }
        });
    }

    private void showDetailsDialog() {
        MySearchResult result = tableView.getSelectionModel().getSelectedItem();
        if(result == null) {
            return;
        }

        try {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("details_dilaog.fxml"));

            Dialog dlg = new Dialog();
            dlg.initOwner(tableView.getScene().getWindow());
            dlg.initModality(Modality.APPLICATION_MODAL);

            dlg.getDialogPane().setContent((Parent) loader.load());
            dlg.getDialogPane().getButtonTypes().setAll(ButtonType.OK);

            DetailsDialogControler ddc = loader.getController();
            ddc.showDetailsFor(result);

            dlg.showAndWait();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
}