를이 내 질문에 내 수업 시간에 지금 목록보기 문제
public class TempStore { // this is a singleton class
public static ObservableList<Filez> files= FXCollections.observableArrayList();
}
모양입니다
ListView<Filez> listfiles = new ListView<>();
listfiles.setItems(TempStore.files);
listfiles.setOrientation(Orientation.VERTICAL);
listfiles.setOnMouseClicked(new EventHandler<Event>() {
@Override
public void handle(Event arg0) {
// TODO Auto-generated method stub
System.out.println(listfiles.getSelectionModel().getSelectedIndex());
}
});
listfiles.setCellFactory((ListView<Filez> l) -> listup);
편집 - 내 liscell 클래스
public class Listupdater extends ListCell<Filez> {
@Override
protected void updateItem(Filez arg0, boolean arg1) {
// TODO Auto-generated method stub
super.updateItem(arg0, arg1);
if(arg0 != null)
setGraphic(view(arg0));
}
@Override
public void updateIndex(int arg0) {
// TODO Auto-generated method stub
super.updateIndex(arg0);
setGraphic(view(TempStore.files.get(arg0)));
}
@Override
public void updateSelected(boolean arg0) {
// TODO Auto-generated method stub
super.updateSelected(arg0);
System.out.println("update selected");
}
@Override
public void startEdit() {
// TODO Auto-generated method stub
super.startEdit();
}
Node view(Filez arg0){
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(2, 2, 2, 2));
try {
System.out.print(arg0.toString());
} catch (Exception e) {
e.printStackTrace();
System.out.print("error caught");
}
Label lab = new Label(arg0.getName());
grid.add(lab, 1, 1);
return grid;
}
}
지금 내 문제는 내가하지 않는 것입니다 아무것도 내 listview에 표시하고 내가 listview 영역을 클릭 system.out.printIn 인쇄 -1 .. 내 목록이 비어 있지 않습니다, 항상 그것에 항목이 .. 승 모자 내가 잘못하고있어 some1 나를 도울 수 있습니다 ...
또한 더 많은 정보를 추가하려면 내 목록보기 tabpane의 탭 중 하나에 넣어지고 .. 만약 누군가가 너무 나에 대해 어떻게 설명 할 수있는 listview 너무, 나는 statisfied 것입니다, 내가 원하는 건 프로그래밍 방식으로 listiview에/del 항목을 넣을 수 있고 노드 목록보기에서 셀을 스타일링 할 수 있습니다. 감사합니다
코드의 마지막 줄을 고칠 수 있습니까? '리스트 업 '이란 무엇입니까? –
오, 죄송합니다 .. listup은 내 listcell 클래스 개체입니다. 제가 게시해야합니까? @James_D –
예, 질문을 수정하고 코드를 게시하십시오. 당신은 또한 귀하의 처리기가 무엇을 해야하는지 설명 할 수 있습니까? 마우스 클릭으로 어떤 동작을 실제로 수행하고 싶습니까? 아니면 선택이 변경 될 때 실제로 무엇인가하고 싶습니까? –