繁体   English   中英

同一列中的两个不同类型的值

[英]two differents types values at the same column

在此处输入图片说明

我有这张表,其中有一列显示数量。 我想要的是显示数量和测量单位,例如

60 meters
10 pieces
20 liters
(the first column)

这是我在表中显示的对象:

公共类 VentaDetalle {

private IntegerProperty idVentaDetalle;
private IntegerProperty idMercancia;
private StringProperty nombreMercancia;
private IntegerProperty idVentaGeneral;
private DoubleProperty cantidad;
private DoubleProperty general;
private DoubleProperty mayoreo;
private DoubleProperty subtotal;

public VentaDetalle(int idMercancia, String nombreMercancia, int idVentaGeneral,
        Double cantidad, double mayoreo, double general, Double subtotal) {
    this.idMercancia = new SimpleIntegerProperty(idMercancia);
    this.nombreMercancia = new SimpleStringProperty(nombreMercancia);
    this.idVentaGeneral = new SimpleIntegerProperty(idVentaGeneral);
    this.cantidad = new SimpleDoubleProperty(cantidad);
    this.mayoreo = new SimpleDoubleProperty(mayoreo);
    this.general = new SimpleDoubleProperty(general);
    this.subtotal = new SimpleDoubleProperty(subtotal);
}

//Metodos atributo: idVentaDetalle
public int getIdVentaDetalle() {
    return idVentaDetalle.get();
}

public void setIdVentaDetalle(int idVentaDetalle) {
    this.idVentaDetalle = new SimpleIntegerProperty(idVentaDetalle);
}

public IntegerProperty IdVentaDetalleProperty() {
    return idVentaDetalle;
}
//Metodos atributo: idMercancia

public int getIdMercancia() {
    return idMercancia.get();
}

public void setIdMercancia(int idMercancia) {
    this.idMercancia = new SimpleIntegerProperty(idMercancia);
}

public IntegerProperty IdMercanciaProperty() {
    return idMercancia;
}

//Metodos atributo: nombreMercancia
public String getNombreMercancia() {
    return nombreMercancia.get();
}

public void setNombreMercancia(String nombreMercancia) {
    this.nombreMercancia = new SimpleStringProperty(nombreMercancia);
}

public StringProperty NombreMercanciaProperty() {
    return nombreMercancia;
}

//Metodos atributo: idVentaGeneral
public int getIdVentaGeneral() {
    return idVentaGeneral.get();
}

public void setIdVentaGeneral(int idVentaGeneral) {
    this.idVentaGeneral = new SimpleIntegerProperty(idVentaGeneral);
}

public IntegerProperty IdVentaGeneralProperty() {
    return idVentaGeneral;
}
//Metodos atributo: cantidad

public Double getCantidad() {
    return cantidad.get();
}

public void setCantidad(Double cantidad) {
    this.cantidad = new SimpleDoubleProperty(cantidad);
}

public DoubleProperty CantidadProperty() {
    return cantidad;
}

//Metodos atributo: general
public Double getMayoreo() {
    return mayoreo.get();
}

public void setMayoreo(Double mayoreo) {
    this.mayoreo = new SimpleDoubleProperty(mayoreo);
}

public DoubleProperty MayoreoProperty() {
    return mayoreo;
}

//Metodos atributo: general
public Double getGeneral() {
    return general.get();
}

public void setGeneral(Double general) {
    this.general = new SimpleDoubleProperty(general);
}

public DoubleProperty GeneralProperty() {
    return general;
}
//Metodos atributo: subtotal

public Double getSubtotal() {
    return subtotal.get();
}

public void setSubtotal(Double subtotal) {
    this.subtotal = new SimpleDoubleProperty(subtotal);
}

public DoubleProperty SubtotalProperty() {
    return subtotal;

我像这样初始化列:

clmnCantidad.setCellValueFactory(new PropertyValueFactory<VentaDetalle, Double>("cantidad"));

我从带有表格项目的数据库中获取单位,该表格具有名称、库存、代码栏和度量单位

我不打算回答关于 SQL 查询的部分 - 理想情况下它应该是某种结合两个表的JOIN语句。

结合IntegerPropertyStringProperty有两种主要方法。

方法一:创建一个新的属性,将它们连接到 Model 类中

public class VentaDetalle {
    private DoubleProperty cantidad;
    private StringProperty measurementUnit;
    private StringProperty cantidadWithUnit;

    // Other properties

    // Public getters/setters

    public VentaDetalle(......) {
        // All the other stuff you did in constructor

        cantidadWithUnit.bind(Bindings.concat(cantidad, " ", measurementUnit));
    }
}

然后你只需要设置单元格值工厂:

clmnCantidad.setCellValueFactory(new PropertyValueFactory<>("cantidadWithUnit"));

方法二:在单元格值工厂回调中串联

clmnCantidad.setCellValueFactory(row ->
     Bindings.concat(row.getValue().cantidadProperty(), " ", row.getValue().measurementUnitProperty())
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM