Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javafx 选项卡图形中的图像视图_Javafx - Fatal编程技术网

Javafx 选项卡图形中的图像视图

Javafx 选项卡图形中的图像视图,javafx,Javafx,我有一个简单的TabUtil类,它为我创建了一个选项卡,标题为ImageView public static Tab createIconTab(ImageView icon) { Tab tab = new Tab(); tab.setGraphic(icon); System.out.println("create tab: +"); icon.setOnMouseClicked(new EventHandler<MouseEvent

我有一个简单的TabUtil类,它为我创建了一个
选项卡
,标题为
ImageView

public static Tab createIconTab(ImageView icon) {
    Tab tab = new Tab();
    tab.setGraphic(icon);
    System.out.println("create tab: +");
    icon.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            System.out.println("CLICKED");
        }
    });
    return tab;
}
公共静态选项卡createIconTab(图像视图图标){
Tab Tab=新选项卡();
tab.设置图形(图标);
System.out.println(“创建选项卡:+”;
icon.setOnMouseClicked(新的EventHandler(){
@凌驾
公共无效句柄(MouseeEvent事件){
System.out.println(“单击”);
}
});
返回选项卡;
}
通过其他三个选项卡,它为我生成了以下UI。如果我点击带有“+”图标的选项卡,什么也不会发生。单击未打印出来。。。我还尝试在图形组件上设置EventHandler。又一次什么都没发生……但为什么


我遇到了一个类似的问题,通过先将ImageView放入标签来解决,如下所示:

public static Tab createIconTab(ImageView icon) 
{
    Label  iconLabel = new Label();
    iconLabel.setGraphic( icon );
    iconLabel.setContentDisplay( ContentDisplay.GRAPHIC_ONLY  );
    iconLabel.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            System.out.println("CLICKED");
        }
    });

    Tab tab = new Tab();
    tab.setGraphic( iconLabel );
    return tab;
}
公共静态选项卡createIconTab(图像视图图标)
{
标签图标标签=新标签();
图标标签。设置图形(图标);
iconLabel.setContentDisplay(仅限ContentDisplay.GRAPHIC_);
setOnMouseClicked(新的EventHandler(){
@凌驾
公共无效句柄(MouseeEvent事件){
System.out.println(“单击”);
}
});
Tab Tab=新选项卡();
tab.设置图形(图标标签);
返回选项卡;
}