내 문제입니다.자바 FX 콤보 <Integer> 유형이 일치하지
내가
- 는 "정수 해"
- 액세스 overcmb_year.getSelectionModel가(). 선택 "INT 년"만들기에 노력했습니다 (새 정수 (년))
- cmb_year을 통해 액세스. getSelectionModel(). select (year)
항상 인수 유형이 일치하지 않습니다.
어떻게 될 수 있습니까? 당신이 선택되어있는 항목을 설정하려는 경우
내 문제입니다.자바 FX 콤보 <Integer> 유형이 일치하지
내가
항상 인수 유형이 일치하지 않습니다.
어떻게 될 수 있습니까? 당신이 선택되어있는 항목을 설정하려는 경우
, 당신은 콤보 상자의 selectionModel의 작업 할 :
cmb_year.getSelectionModel().select(cmb_year.getItems().indexOf(year));
또한 setSelectedItem(year)
또는 selectLast()
을 시도 할 수 있습니다.
올바르게 기억하면 ComboBox API는 이미 ComboBox의 목록보기에있는 경우 선택한 항목을 setValue()에 지정된 값으로 자동 설정합니다. – scottb
이것은 단순히 제대로 또는 완전하게 초기화되지 않는 ComboBox의 문제 일 수 있습니다. ComboBoxes를 "사용하지 않은"절대로 사용하지 않습니다. 몇 줄의 코드를 사용하여 설정합니다. 여기
// this first line gets the data from my data source
// the ComboBox is referenced by the variable 'cbxInst'
ObservableList<Institution> ilist = Institution.getInstitutionList();
Callback<ListView<Institution>, ListCell<Institution>> cellfactory =
new Callback<ListView<Institution>, ListCell<Institution>>() {
@Override
public ListCell<Institution> call(ListView<Institution> p) {
return new InstitutionListCell();
}
};
cbxInst.setCellFactory(cellfactory);
cbxInst.setButtonCell(cellfactory.call(null));
cbxInst.setItems(ilist);
핵심 포인트됩니다 :
내 대화 컨트롤러 클래스 중 하나의 초기화() 메소드에서 코드 발췌 (기관 개체 목록이 콤보 상자가 표시됩니다)되어 다음
ComboBox가 표시 할 ListCell 인스턴스를 생성하는 셀 팩터 리를 정의합니다.
버튼 셀을 초기화하기 위해 공장을 사용하여 ListCell 인스턴스를 만듭니다. 당신은 유사한 방식으로 콤보를 초기화한다면
private final class InstitutionListCell extends ListCell<Institution> {
@Override
protected void updateItem(Institution item, boolean empty){
super.updateItem(item, empty);
if (item != null) {
this.setText(item.getName());
} else {
this.setText(Census.FORMAT_TEXT_NULL);
}
}
}
, 그것은 당신의 문제가 있음을 수 있습니다 : 완성도를 들어
, 여기에 기관은 listcell 인스턴스가 만들어지는에서 개인 회원 클래스 해결 될 것입니다.
런타임 또는 컴파일 오류입니까? –
런타임, 컴파일 타임의 경고조차 없음 – billdoor
'StringConverter'을 사용합니까? –