0

私はポッドキャストプレーヤーを書いていて、表示するファイルのリストを持っています。

ユーザーがエントリをダブルクリックすると、そのファイルが再生されます。彼らが別のものを選択した場合。リストで何が選択されているかわかりません。アイデアは、再生中のファイルを別の色で強調表示することです。別のファイルを選択する機能を引き続き保持します (その機能を失いたくない)。ほとんどのオーディオ プレーヤーは同じ原理で動作します。

このJavaFXテーブルビューの色を見てみましたが、これはデータに基づいて行の色を変更します. ただし、データが変更された場合、データが変更されても行の色は更新されません。

セル ファクトリを含むテーブルがあり、変数 "isSelectedFile" に基づいてセル スタイルを設定しました。

ロード時に isSelectedFile=True の場合はすべて問題ありませんが、行がテーブルビューにロードされている間にデータを変更すると、更新されません。

私の細胞工場は次のとおりです。

entryDisplayNameColumn.setCellFactory(new Callback<TableColumn<PlaylistEntry, String>, TableCell<PlaylistEntry, String>>() {
            @Override
            public TableCell call(TableColumn p) {

                TableCell cell = new TableCell<Task, Object>() {
                    @Override
                    public void updateItem(Object item, boolean empty) {
                        super.updateItem(item, empty);
                        setText(empty ? null : getString());
                        setGraphic(null);
                        TableRow currentRow = getTableRow();
                        PlaylistEntry ple = currentRow == null ? null : (PlaylistEntry) currentRow.getItem();

                        if (ple != null) {
                            clearPriorityStyle();
                            setPriorityStyle(ple.isSelectedFile());
                        }
                    }

                    @Override
                    public void updateSelected(boolean upd) {
                        super.updateSelected(upd);
                        System.out.println("is update");
                    }

                    private void clearPriorityStyle() {
                        ObservableList<String> styleClasses = getStyleClass();
                        styleClasses.remove("priorityLow");
                        styleClasses.remove("priorityMedium");
                        styleClasses.remove("priorityHigh");
                    }

                    private void setPriorityStyle(boolean activeValue) {
                        if (activeValue) {
                            getStyleClass().add("priorityLow");
                        } else {
                            getStyleClass().add("priorityMedium");
                        }
                    }

                    private String getString() {
                        return getItem() == null ? "" : getItem().toString();
                    }
                };
                return cell;
            }
        });

私のCSS:

.priorityLow { 
-fx-control-inner-background: snow;
-fx-accent: derive(-fx-control-inner-background, -40%);
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
}

.priorityMedium { 
-fx-control-inner-background: #1d1d1d;
-fx-accent: derive(-fx-control-inner-background, -40%);
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
 }
4

1 に答える 1

2

これを試してみてください...

tablecol.setCellFactory(new Callback<TableColumn<CheckDo, String>, TableCell<CheckDo, String>>() {

        @Override
        public TableCell<CheckDo, String> call(TableColumn<CheckDo, String> p) {


             return new TableCell<CheckDo, String>() {

            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (!isEmpty())
                    this.setStyle("-fx-background-color:red");
                    this.getTableRow().setStyle("-fx-background-color:red");
                        setText(item);
                }
            }
        };
于 2013-11-05T10:43:23.147 に答える