2014-06-08 32 views
0

我目前有一個ListView,它可以在Width中調整大小,並使用返回我自定義的ListCell對象的自定義CellFactory。JavaFX ListCell啓用橫向增長

我已經閱讀: Customize ListView in JavaFX with FXML和我使用了類似的結構就像提到的:

public class ListViewCell extends ListCell<String>{ 
@Override 
public void updateItem(String string, boolean empty){ 
    super.updateItem(string,empty); 
    if(string != null) { 
     ... 
     setGraphic(myComponent); 
    } 
} 

我想myComponent採取全尺寸可用的的ListCell內,但它似乎setGraphic方法限制了給定節點的大小。

如果需要,我可以提供我所有的代碼,但是我不確定哪些部分是相關的,我不想發佈大量代碼。

回答

0

現在我解決我的問題,這裏是如何:

class MyListCell extends ListCell<MyObject> 
{ 
    private final AnchorPane _myComponent; 

    public MyListCell() 
    { 
     ... 
     this.setPrefWidth(0); 
     myComponent.prefWidthProperty().bind(this.widthProperty()); 
    } 

    ... 

    @Override 
    protected void updateItem(MyObject item, boolean empty) 
    { 
     ... 
     setGraphic(_myComponent); 
     ... 
    } 
} 

如果this.setPrefWdith(0)被忽略,myComponent會在ListCell內部增長,但是如果我縮小ListView,Cell不會縮小。

0

嘗試或者通過CSS或通過API,從而提供了極大的擴展whithin容器控件的prefWidth屬性設置爲Infinity

myComponent.setStyle("-fx-pref-width: Infinity"); 
+0

我試過'myComponent.prefWidth(Double.MAX_VALUE);',但是這沒有可見的效果。 – quantumbyte

相關問題