//this is the button that add objects to the table cells
@FXML
private void OK01(ActionEvent event)
{
rImg20.setVisible(false);
tv.setVisible(true);
String combo022 = combo02.getValue().toString();
Integer result = Integer.valueOf(prCombo01.getText());
del01.setVisible(true);
data.add(new InvoiceEntry(
(String) combo01.getValue(),
combo022,
(String) combo03.getValue(),
(String) combo04.getValue(),
(Integer)prCombo01.getText())); //but i cant get this label to add to the
integer column (price) of the table
}
我已经编写了每个应该发生这种情况的代码,例如... InvoiceEntry.java及其.fxml。请大家帮帮我#34;请问我如何解决这个问题"。我可以告诉你其他代码,如果你想,因为我不知道我怎么能一次发布所有堆栈交换
这是代码的完成。
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 );
}
}
FXML
@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);
}
//this is the button that adds objects to the table cells
@FXML
private void OK01(ActionEvent event)
{
rImg20.setVisible(false);
tv.setVisible(true);
String combo022 = combo02.getValue().toString();
Integer result = Integer.valueOf(prCombo01.getText());
del01.setVisible(true);
data.add(new InvoiceEntry(
(String) combo01.getValue(),
combo022,
(String) combo03.getValue(),
(String) combo04.getValue(),
(Integer)prCombo01.getText()));//but i cant get this label to add to the
integer column (price) of the table
}
答案 0 :(得分:0)
Java是一种强类型语言,您不能只将String
强制转换为Integer
,但是您可以使用Integer.parseInt
但是您应该准备好解析可能会使用{{1}如果string实际上不是整数。
还有一件事,“价格”可能不是NumberFormatException
/ int
,很可能你想要使用BigDecimal
代替(但是,请,请永远不要使用{{ 1}} / Integer
或double
/ Double
与金钱有关的任何事情!)。可以使用this constructor
float
创建Float