我正在尝试将一个值添加到我在Scene Builder中创建的名为nameComboBox的可编辑组合框中。
我使用以下代码填充组合框:
private ObservableList<String> getNames()
{
return (FXCollections.observableArrayList("Freddy","Kerstin"));
}
..
nameComboBox.getSelectionModel().select(getNames());
我在Scene Builder中定义了一个Save按钮。代码如下所示:
@FXML
private void handleSaveBtn()
{
System.out.println("The new name is " + nameComboBox.getValue());
}
当显示场景时,组合框可编辑字段显示为空,两个名称隐藏在空字段下面的列表中,这就是我想要发生的事情。
然后键入&#34; Rusty&#34;在空字段中单击一个保存按钮,所有发生的事情都是println语句返回 &#34;新名称为空&#34;。
如果我想对新值执行某些操作,例如验证它或将其存储在数据库中,如何获取我在可编辑字段中输入的值?
答案 0 :(得分:0)
尝试使用此代替var SchemaDefintion = new SchemaDefinition();
for (int Currentsheet = 1; Currentsheet <= WorksheetCount; Currentsheet=Currentsheet+1)
{
Excel.Worksheet worksheet = workbook.Sheets[Currentsheet];
string SheetName = worksheet.Name;
if (SheetName.Substring(0, 2) != "A" || SheetName.Substring(0, 2) != "B")
{
//Error that invalid excel sheet
}
Excel.Range range = worksheet.UsedRange;
var ListFields = new List<FieldInfo>();
for (int row = 2; row <= range.Rows.Count; row++)
{
var Fieldproperties = new FieldInfo {Name = ((Excel.Range)range.Cells[row, 1]).Text, Description = ((Excel.Range)range.Cells[row, 2]).Text,
Length =Convert.ToInt32(((Excel.Range)range.Cells[row, 3]).Text),
Start=Convert.ToInt32( ((Excel.Range)range.Cells[row, 4]).Text),
End=Convert.ToInt32( ((Excel.Range)range.Cells[row, 5]).Text),
Format= ((Excel.Range)range.Cells[row, 6]).Text
};
ListFields.Add(Fieldproperties);
}
SchemaDefintion.Input.Add(new testing.Models.RecordInfo { RecordId = "A", Name = "header", Description = "description", FieldInfo = ListFields });
:
SchemaDefintion.Input.Add(new testing.Models.RecordInfo { RecordId = "A", Name = "header", Description = "description", FieldInfo = ListFields });`
这会返回可编辑.getValue()
的{{1}}(nameComboBox.getEditor().getText()
)textProperty
的值。
答案 1 :(得分:0)
试试这个
nameComboBox.setItems(getNames());
nameComboBox.setValue("Freddy");