2014-06-16 100 views
0

我有TableViewRoads,列Name和列Number of LanesNumber of Lanes顯示一個整數,即一條道路的車道數。當添加一條新道路時,我有另一個TableView設置車道的屬性。我Lane類是:JavaFX:將TableView列綁定到另一個TableView的行數

public class Lane { 

    private StringProperty name; 

    private FloatProperty width; 

    private BooleanProperty normalDirection; 

    public Lane(String name, float width, boolean normalDirection) { 
     this.name = new SimpleStringProperty(name); 
     this.width = new SimpleFloatProperty(width); 
     this.normalDirection = new SimpleBooleanProperty(normalDirection); 
    } 

    public void setName(String value) { 
     nameProperty().set(value); 
    } 

    public String getName() { 
     return nameProperty().get(); 
    } 

    public StringProperty nameProperty() { 
     if (name == null) { 
      name = new SimpleStringProperty(this, "name"); 
     } 
     return name; 
    } 

    public void setWidth(float value) { 
     widthProperty().set(value); 
    } 

    public float getWidth() { 
     return widthProperty().get(); 
    } 

    public FloatProperty widthProperty() { 
     if (width == null) { 
      width = new SimpleFloatProperty(this, "width"); 
     } 
     return width; 
    } 

    public void setNormalDirection(boolean value) { 
     normalDirectionProperty().set(value); 
    } 

    public boolean getNormalDirection() { 
     return normalDirectionProperty().get(); 
    } 

    public BooleanProperty normalDirectionProperty() { 
     if (normalDirection == null) normalDirection = new SimpleBooleanProperty(this, "normalDirection"); 
     return normalDirection; 
    } 
} 

我試圖創建一個類Road,我想一個屬性private IntegerProperty numberOfLanes綁定在車道TableView使用的ObservableList<Lane>的大小,但我不知道什麼是最好的方式來做到這一點。

我是JavaFX世界的新手和任何幫助表示讚賞。先謝謝了。

回答

0

你是否在尋找類似:

public class Road { 
    private final ObservableList<Lane> lanes = FXCollections.observableArrayList(); 
    public final ObservableList<Lane> getLanes() { 
     return lanes ; 
    } 

    private final ReadOnlyIntegerWrapper numberOfLanes = new ReadOnlyIntegerWrapper(this, "numberOfLanes"); 
    public final int getNumberOfLanes() { 
     return numberOfLanes.get(); 
    } 
    public ReadOnlyIntegerProperty numberOfLanesProperty() { 
     return numberOfLanes.getReadOnlyProperty(); 
    } 

    public Road() { 
     numberOfLanes.bind(Bindings.size(lanes)); 
    } 
} 
+0

它的工作原理。謝謝! – Giorgio