###前提・実現したいこと
JavaFXで設置したTableViewについて、
並べ替えをするコードの書き方が分かりません><
testTable table = new testTable();
table.addData("あああ",1,4)
table.addData("いいい",9,6)
table.addData("ううう",5,2)
といったように、tableViewにデータを追加した後
「Bの列の数字が大きい順に並べ替えをする」というコードは、どのように書けばいいのでしょうか?
アプリケーションを実行中、tableViewの列ヘッダーをクリックしてソートすることはできるので、
それと同じ様な感じに並べ替えしたいのですが・・・
質問に不足な点などあったらご指摘下さい。
よろしくお願いします(T_T)
###testController
Java
1public class testController implements Initializable { 2 @Override 3 public void initialize(URL location, ResourceBundle resources) { 4 testTable.setTable(testTable); 5 } 6 @FXML 7 private TableView<testTable.testTableData> testTable;
###testTable
Java
1 private static TableView<testTableData> table; 2 private static ObservableList<testTableData> data = FXCollections.observableArrayList(); 3 4 public static void setTable(TableView<testTableData> table) { 5 testTable.table = table; 6 new testTable().createTableView(); 7 } 8 9 public ObservableList<testTableData> getTableDatas() { 10 return data; 11 } 12 13 public void addData(String aStr, Integer bInt, Integer cInt) { 14 data.add(new testTableData(aStr, bInt, cInt)); 15 } 16 17 @SuppressWarnings("unchecked") 18 public TableView<testTableData> createTableView() { 19 20 TableColumn<testTableData, String> columnA = new TableColumn<testTableData, String>("A"); 21 TableColumn<testTableData, Integer> columnB = new TableColumn<testTableData, Integer>("B"); 22 TableColumn<testTableData, Integer> columnC = new TableColumn<testTableData, Integer>("C"); 23 24 table.getColumns().addAll(columnA, columnB, columnC); 25 table.setItems(data); 26 27 return table; 28 } 29 30 31 public class testTableData { 32 private String aStr; 33 private Integer bInt; 34 private Integer cInt; 35 36 public testTableData(String aStr, Integer bInt, Integer cInt,) { 37 this.aStr = aStr; 38 this.bInt = bInt; 39 this.cInt = cInt; 40 } 41 42 public String getAStr() { 43 return aStr; 44 } 45 46 public void setAStr(String aStr) { 47 this.aStr = aStr; 48 } 49 50 public Integer getBInt() { 51 return bInt; 52 } 53 54 public void setBInt(Integer bInt) { 55 this.bInt = bInt; 56 } 57 58 public Integer getCInt() { 59 return cInt; 60 } 61 62 public void setCInt(Integer cInt) { 63 this.cInt = cInt; 64 } 65 } 66} 67

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/20 05:14
2017/06/20 05:20