2014-01-21 39 views
1

我有一個簡單的TabUtil-Class,它爲我創建了一個Tab,並將一個被寬恕的ImageView作爲標題。ImageView in Tab圖形

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; 
} 

與其他三個選項卡它會生成以下用戶界面。如果我點擊帶有「+」的標籤 - 圖標沒有任何反應。 CLICKED不是打印出來的......我也嘗試在圖形組件上設置EventHandler。再次沒有任何反應......但爲什麼?

Tabs Screenshot

回答

3

我也曾有過類似的問題,通過將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; 
}