子fxml文件未加载到父fxml [英] child fxml file not loading to parent fxml

查看:75
本文介绍了子fxml文件未加载到父fxml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我们新来的fxml所以请忽略我的愚蠢问题
这里有一些我试用2天但没有成功的事情

hello guys i m new to fxml so please ignore my silly question here are few things which i m try for 2 day but got not success


  1. 从表中删除空格,即表格大小应该达到
    可用行数(行数不同)

  2. 当用户点击表格时行(任何显示值)新的fxml文件在
    中打开锚定窗格(显示tableview)为tableview分配但我想在主视图中显示它(整个事物表和2个文本字段和此主要后面的搜索按钮)我想在这里显示堆栈)
    主视图(其他fxml文件只有标题和侧边栏)

  1. remove white space from table i.e table size should be up to number of available row(number of row varies)
  2. when user click on table row(any display value) new fxml file is open in Anchor pane(tableview is displayed) allotted for tableview but i want to display it in main view (where whole thing table and 2 text field and search button behind this main stack i want to display here) main view (other fxml file which has only have header and sidebar)

如下图所示
table
所需事物的图像

这是我的代码

   public void initialize(URL location, ResourceBundle resources) {
    databaseHandler = DatabaseHandler.getInstance();
    initCol();

        String qu = "SELECT * FROM country_tbl ";
        ResultSet rs = databaseHandler.execQuery(qu);
            try {
                while (rs.next()) {
                 String id= rs.getString("id");
                 String name= rs.getString("countryname");
                 String description = rs.getString("descr");
                 String country2char= rs.getString("country2char");
                 String descrshort = rs.getString("descrshort");
                 data.add(new addcountryController(id,name, description,country2char,descrshort));
                }
            }catch (SQLException ex) {
                Logger.getLogger(addcountryController.class.getName()).log(Level.SEVERE, null, ex);
            }

         tableUser.setItems(null);
         tableUser.setItems(data);

         tableUser.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
         tableUser.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<addcountryController>() {
         public void onChanged(ListChangeListener.Change<? extends addcountryController> c) {
             try {

                 FXMLLoader loader =new FXMLLoader();
                 loader.load(getClass().getResource("/region/updatecountry.fxml").openStream());

                 updatecountryController usercontroller=(updatecountryController)loader.getController();
                    for (addcountryController p : c.getList()) {
                     String ADDID=p.getId();
                     String ADD=p.getName();    
                     String ADD1=p.getDescriptionshort();
                     String ADD2=p.getDescription();
                     String ADD3=p.getCountrychar();
                     usercontroller.setText(ADDID,ADD,ADD1,ADD2,ADD3);
                   }                     
                    StackPane root = loader.getRoot();
                    stackmain.getChildren().clear();
                    stackview.getChildren().add(root);     

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


推荐答案

这里的第一点是解决方案:
您可以在 tableView 中设置您的cellSize,然后您就可以将它用于行高(我发现这是获取行高度的最简单方法) )。
之后,您必须将表的 prefHeight 绑定到您的数据大小,如下所示:

Hi for the first point here is the solution: You can set your cellSize in the tableView, then you will be able to use it for row getting heights(I found this the simplest way to get the rows' height). After that you have to bind the table's prefHeight to the size of your data like this:

tableView.setFixedCellSize(20);
tableView.prefHeightProperty().bind(Bindings.size(data).multiply(tableView.getFixedCellSize()).add(30));

有一个 .add(30)因为你必须添加tableHeaderRow的大小,这是最简单的方法,做一些实验并明确设置该值。如果你想得到确切的值,你可以通过 .lookup s来获得 TableHeaderRow 然后得到它高度。

There is an .add(30) because you have to add the tableHeaderRow's size, and this is the simplest way, to do a little experimentation and set that value explicitly. If you want the get the exact value, you can do it via .lookups to get the TableHeaderRow then get its height.

我真的不明白你的第二个问题你想在哪里显示它。您可以使用FXMLLoader加载该视图并添加到该视图中,但是如果您指定一点点更好您想要添加的位置(其中 .fxml ,以及如何与包含该表的 .fxml 链接。

I don't really understand your second problem where do you want to display it. You can use the FXMLLoader to load that view and add to it, but if you specify a little bit better where do you exactly want to add(in which .fxml, and how is linked with the .fxml that contains the table).

这篇关于子fxml文件未加载到父fxml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆