根节点(TreeItem)未在TreeView中显示

 kg9854997 发布于 2023-02-10 14:32

我在.fxml文件中创建TreeView,然后我尝试显示根节点.但它没有显示出来.

这是我的代码.


                  
                    
                  
                  
                    
                      
                        
                          
                            
                              
                                
                                  
                                    
                                      
                                    
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                      

我也在主要类中给出了这个参考.

public class Mainextends Application {
@FXML
public TreeView soariteTree;
@FXML
public TreeItem rootTreeItem;

请给我任何参考或提示.

1 个回答
  • 你用fxml做了一个小错误,

    你可以看到你写的AnchorPane.rightAnchor="167.0"是你的树视图消失了(同样的小错误,锚窗格和树视图的宽度).

    用,替换你的滚动窗格,

    <ScrollPane fx:id="soariteTreeScrollPane" pref pref AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                                  <content>
                                    <AnchorPane id="Content" fx:id="soariteTreeAnchorPane" min min pref pref>
                                      <children>
                                        <TreeView fx:id="soariteTree" pref pref showRoot="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                                          <TreeItem expanded="true" value="categories" fx:id="rootTreeItem" />
                                        </TreeView>
                                      </children>
                                    </AnchorPane>
                                  </content>
                                </ScrollPane>
    

    更新: - 处理鼠标事件

    soariteTree.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if (event.getButton().equals(MouseButton.SECONDARY)) {
                    System.out.println(">> " + event.getEventType());
                }
            }
        });
    

    2023-02-10 14:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有