JavaFX: обвържете колона TableView с броя редове на друг TableView

Имам TableView от Roads с колона Name и колона Number of Lanes. Number of Lanes показват цяло число, което е броят на лентите на пътя. Когато добавя нов път, имам друг TableView, където задавам свойствата за лента. Моят Lane клас е:

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 с размера на ObservableList<Lane>, използвано в TableView от ленти, но не знам кой е най-добрият начин да го направя.

Аз съм начинаещ в света JavaFX и всяка помощ е благодарна. Благодаря предварително.


person Giorgio    schedule 16.06.2014    source източник


Отговори (1)


Търсите ли нещо като:

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));
   }
}
person James_D    schedule 16.06.2014