2017-04-22 29 views
0

我想讓我的列表單元格在懸停時顯示爲「指針」/「保持」遊標。 我已經設法瞄準整個listView並添加了背景色等,但它就像列表單元格不存在一樣。我是否需要手動設置細胞工廠?爲什麼不能修改ListView中的list-cell css?

編輯: 我得到了答案,我不需要手動指定單元格,調用.list-cell應該足以添加樣式。我的CSS應該工作得很好,因爲我管理改變其他元素的背景顏色,而不是.list-cell。我也曾嘗試FX-光標

EDIT2: 我現在已經scenebuilder預覽中測試>場景樣式表>添加一個樣式表,以及文檔中我把:

.list-cell{ 
-fx-cursor: pointer; 
} 
.test{ 
-fx-background-color: black; 
} 

仍然沒有去的時候我預覽了示例數據。

編輯3: Screenshot 光標不顯示在屏幕截圖中,但我可以告訴你,我的CSS工作,只是不在列表單元格。

到目前爲止,我已經試過:

CSS:

.list-cell{ 
    -fx-background-color:black; 
    -fx-cursor: pointer; 
} 
#test .list-cell{ 
    -fx-background-color:black; 
    -fx-cursor: pointer; 
} 
.test .list-cell{ 
    -fx-background-color:black; 
    -fx-cursor: pointer; 
} 

JAVA:

teamListView.setCellFactory(new Callback<ListView<String>, 
javafx.scene.control.ListCell<String>>() 
     { 
      @Override 
      public ListCell<String> call(ListView<String> teamListView) 
      { 
       return new ListCell(); 
      } 
     }); 

代碼:

我的控制器:

public class MainPageController implements Initializable { 
    public static ObservableList<String> data = 
FXCollections.observableArrayList(); 

    @FXML 
    private Label label; 
    @FXML 
    private ListView<String> teamListView; 

    @Override 
    public void initialize(URL url, ResourceBundle rb) { 
     Team escala = new Team("Escala", "Conrad Adams", 4987000); 
     ArrayList<Team> teams = new ArrayList<Team>(); 
     teams.add(escala); 
     data.add(teams.get(0).getName()); 
     teamListView.setItems(data); 

    }  

} 
+0

您不需要自定義cellFactory,但第二個css規則無效。此外,你從來沒有使用'-fx-cursor'屬性......我們也不能確定你實際上是使用'id'作爲列表單元的祖先的id。 – fabian

+0

即時通訊只是使用背景顏色作爲測試,背景是不會改變這是問題 – Softy

+0

你有沒有正確地添加樣式表?該CSS應該工作,當我測試它... – fabian

回答

0

我得到了一個解決方法,我沒有,雖然一個解釋:

改變

.list-cell{ 
-fx-cursor: hand; 
} 

.list{ 
} 
.list-cell:filled:hover{ 
-fx-cursor: hand; 
-fx-text-fill: dimgrey; 
} 

我的第一個CSS元素似乎以某種方式忽略,它們的位置可能變激活

相關問題