如何获取标签以将其值添加到javafx中的表视图中的整数字段或列

时间:2017-03-17 18:57:17

标签: java javafx javafx-tableview

这是代码

@FXML
private void OK01(ActionEvent event) 
{
 rImg20.setVisible(false);
 tv.setVisible(true);


 String combo022 = combo02.getValue().toString();

 del01.setVisible(true);

 data.add(new InvoiceEntry(
 (String) combo01.getValue(),
 combo022,   
 (String) combo03.getValue(),
 (String) combo04.getValue(),

 (Integer)prCombo01.getText()));       //Here is the problem, i cant get this label to 
 add its value to the integer column (price) of the table 
}

这里是代码的其余部分: InvoiceEntry.java

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TableColumn;

public class InvoiceEntry 
{
private final SimpleStringProperty clothe;
private final SimpleStringProperty pattern;
private final SimpleStringProperty designer;
private final SimpleStringProperty color;
private final SimpleIntegerProperty price;

public InvoiceEntry(
String clothe,
String pattern,
String designer,
String color,
Integer price
) 

{
this.clothe = new SimpleStringProperty( clothe );
this.pattern = new SimpleStringProperty( pattern);
this.designer = new SimpleStringProperty( designer );
this.color = new SimpleStringProperty( color );
this.price = new SimpleIntegerProperty( price );
}

public String getClothe() 
{
return clothe.get();
}

public void setClothe(String iName) 
{
this.clothe.set( iName );
}

public String getPattern() 
{
return pattern.get();
}

public void setPattern(String iName) 
{
this.pattern.set( iName );
}


public String getDesigner() 
{
return designer.get();
}

public void setDesigner(String iName) 
{
this.designer.set( iName );
}

public String getColor() 
{
return color.get();
}

public void setColor(String iName) 
{
this.color.set( iName );
}

public Integer getPrice() 
{
return price.get();
}

public void setPrice(Integer iName) 
{
this.price.set( iName );
}
}

FXMLCONTROLLER.java

@FXML
private TableView tv;
@FXML
private TableColumn<InvoiceEntry, String> clothe;
@FXML
private TableColumn<InvoiceEntry, String> pattern;
@FXML
private TableColumn<InvoiceEntry, String> designer;
@FXML
private TableColumn<InvoiceEntry, String> color;
@FXML
private TableColumn<InvoiceEntry, Integer> price;
@FXML
private ComboBox combo01;
@FXML
private ColorPicker combo02;
@FXML
private ComboBox combo03;
@FXML
private ComboBox combo04;
@FXML
private Label prCombo01;
private ObservableList<InvoiceEntry> data;

@Override
public void initialize(URL url, ResourceBundle rb) 
{
    clothe.setCellValueFactory(
    new PropertyValueFactory<InvoiceEntry, String>("clothe") );

    pattern.setCellValueFactory(
    new PropertyValueFactory<InvoiceEntry, String>("pattern") );

    designer.setCellValueFactory(
    new PropertyValueFactory<InvoiceEntry, String>("designer") );

    color.setCellValueFactory(
    new PropertyValueFactory<InvoiceEntry, String>("color") );

    price.setCellValueFactory(
    new PropertyValueFactory<InvoiceEntry, Integer>("price") );

    data = FXCollections.observableArrayList(
    new InvoiceEntry("", "", "", "", 0));
    tv.setItems(data);
}

这是一个更新&#34;我如何获得一个标签,将其值添加到javafx&#34;的表视图中的整数字段或列中。请问我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

怎么样:

data.add(new InvoiceEntry(
 (String) combo01.getValue(),
 (String) combo02.getValue(),   
 (String) combo03.getValue(),
 (String) combo04.getValue(),
 Integer.parseInt(Combo01.getText())));