【问题标题】:JavaFX: bind TableView column with number of rows of another TableViewJavaFX:将 TableView 列与另一个 TableView 的行数绑定
【发布时间】:2014-08-06 04:27:20
【问题描述】:

我有一个TableView 和一个Roads,其中有一列Name 和一列Number of LanesNumber 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 与车道 TableView 中使用的 ObservableList<Lane> 的大小绑定,但我不知道是什么最好的方法。

我是JavaFX 世界的新手,感谢您提供任何帮助。提前致谢。

【问题讨论】:

    标签: tableview javafx-8


    【解决方案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));
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-28
      • 2023-03-12
      • 2017-04-16
      • 2012-05-28
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      相关资源
      最近更新 更多