私はtableViewにマップするボードモデルを持っています。選択範囲全体を印刷することはできますが、選択範囲の各行を特殊な書式で印刷しようとしています。ここ は、モデルObservableList <ObsevableList <ObsevableList <String>>テーブルビューの項目を一度に1つずつ出力する
public class Board (String pieceno, String avge, String lpte, String lptloc, String grade) {
String PcNo;
String AvgE;
String LptE;
String LptLoc;
String Grade;
public Board({
this.PcNo = pieceno;
this.AvgE = avge;
this.LptE = lpte;
this.LptLoc = lptloc;
this.Grade = grade;
}
public String getPcNo() {
return PcNo;
}
public void setPcNo(String pcno) {
PcNo = pcno;
}
pubic String getAvgE() {
return AvgE;
}
public void setAvgE(String avge) {
AvgE = avge;
}
public String getLptE() {
return LptE;
}
public void setLptE(String lpte) {
LptE = lpte;
}
public String getLptLoc() {
return LptLoc;
}
public void setLptLoc(String lptloc) {
LptLoc = lptloc;
}
public String getGrade() {
return Grade;
}
public void setGrade(String gr) {
Grade = gr;
}
@Override
public String toString() {
return getPcNo() + "," + getAvgE() + "," + getLptE()
+ "," + getLptLoc() + "," + getGrade() + "\n";
}
}
が今ここにtableViewと複数行の選択のためのコードはあります。
TableView tableView = new TableView();
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
TableColumn pcNoCol = new TableColumn();
pcNoCol.setText("pcNo");
pcNoCol.setCellValueFactory(new PropertyValueFactory("pcNo"));
tableView.getColumns().add(pcNoCol);
TableColumn avgECol = new TableColumn();
avgECol.setText("avgE");
avgECol.setCellValueFactory(new PropertyValueFactory("avgE"));
tableView.getColumns().add(avgECol);
TableColumn lptECol = new TableColumn();
lptECol.setText("lptE");
lptECol.setCellValueFactory(new PropertyValueFactory("lptE"));
tableView.getColumns().add(lptECol);
TableColumn lptLocCol = new TableColumn();
lptLocCol.setText("lptLoc");
lptLocCol.setCellValueFactory(new PropertyValueFactory("lptLoc"));
tableView.getColumns().add(lptLocCol);
TableColumn gradeCol = new TableColumn();
gradeCol.setText("grade");
gradeCol.setCellValueFactory(new PropertyValueFactory("grade"));
tableView.getColumns().add(gradeCol);
//Bindings.
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
tableView.itemsProperty().bind(service.valueProperty());
今すぐ行をつかみ、selectedItemsのをプリントアウトマウスイベントは、コードは動作しますが、その代わりのprintln(selectedItemsの)の
tableView.setOnMousePressed((MouseEvent event) -> {
ObservableList<ObservableList<String>>selectedItems = tableView.getSelectionModel().getSelectedItems();
//selectedItems.forEach(selecteditem -> System.out.println(selecteditem));
System.out.println(selectedItems);
});
である私は私がしようと、個々の選択した項目を印刷したいですforeach行の上にコメントアウトされている行。私は次のエラーが発生します。
Executing /home/jimbo/NetBeanProjects/AccountFXFrontEnd/dist/run12421/AccountFXFrontEnd.jar usring platform /usr/java/jdk1.8.0_91/jre/bin/java
Exception in thread"JavaFX Application Thread" java.lang.ClassCastException: accountfxfrontend model Board cannot be cast to javafx.collections.ObservableList
at java.lang.Iterable.forEach Iterable.java.75
コレクションではなく各アイテムを印刷するために私が何をする必要があるか教えてもらえますか?ありがとう。
私はJavaFXのと私は助けに感謝のコレクションに新しいだということは明らかであろう。..
神保
ここでバインドするデータ型は何ですか? tableView.itemsProperty()。bind(service.valueProperty()); –