JavaFX 2.1 TableView refresh items
Mam taki powszechny problem, jak się wydaje. Mój widok tabeli nie odświeży moich elementów po ich zresetowaniu. Sprawdziłem Dane i są nowe.
Próbowałem wielu rozwiązań z internetu, ale bez powodzenia.
Nie można zresetować wszystkich kolumn, ponieważ dodaje jedną pustą jedną dodatkową (Nie wiem dlaczego), a zmiana rozmiaru po prostu łamie.
Moja tabela nie jest edytowalna . Nowe dane są zmieniane.
Dane są odświeżane, Jeśli zmienię kolejność zmiany pozycji i wierszy (:/).
Zostaję bez pomysłów.W tej chwili odświeżanie kodu jest dość proste.
ObservableList<User> data = FXCollections.observableArrayList(User.getResellers());
reseller_table.setItems(data);
Ponownie nowe dane są poprawne. Gdy dokonam wyboru do widoku tableView zwraca nową poprawną pozycję.
24 answers
Miałem podobny problem z odświeżaniem. Moim rozwiązaniem było ograniczenie operacji na ObservableList
do tych, które działają poprawnie z bind()
.
Załóżmy, że ObservableList obsList
jest podstawową listą TableView
.
wtedyobsList.clear()
(dziedziczone z java.util.List<>
) nie zaktualizuje TableView
poprawnie, ale
Również wywołanie setItem(obsList)
czy nie działa , aby uruchomić odświeżanie...ale...
obsList.removeAll(obsList)
(nadpisane przez ObservableList
) działa dobrze ponieważ odpala / align = "left" /
Uzupełnianie listy o zupełnie nową zawartość działa w następujący sposób:
obsList.removeAll(obsList);
obsList.add(...); //e.g. in a loop...
Lub
obsList.removeAll(obsList);
FXCollections.copy(obsList, someSourceList)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-04 10:59:07
Obejście:
tableView.getColumns().get(0).setVisible(false);
tableView.getColumns().get(0).setVisible(true);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-27 03:45:16
Ponieważ JavaFX 8u60
możesz użyć (zakładając, że tableView
jest instancją klasy TableView ):
tableView.refresh();
Z dokumentacji:
Wywołanie refresh () wymusza odtworzenie kontrolki TableView i ponownie zaludnić komórki niezbędne do wypełnienia wizualnych granic Kontrola. Innymi słowy, zmusza to Widok TableView do aktualizacji tego, co pokazuje użytkownikowi. Jest to przydatne w przypadkach, gdy podstawowe źródło danych zmieniło się w sposób, który nie jest obserwowany przez TableView siebie.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-24 00:46:50
UPDATE:
Wreszcie odświeżanie tableview zostało rozwiązane w JavaFX 8u60 , który jest dostępny dla wczesnego dostępu.
O odświeżaniu zobacz aktualizowanie wierszy w Tableview.
A o pustej kolumnie patrz JavaFx 2 create TableView with single column . Zasadniczo nie jest to kolumna, tzn. nie można wybrać elementu klikając na puste pozycje kolumn. Jest to po prostu pusty obszar stylizowany na wiersz.
UPDATE: If aktualizujesz widok tableView za pomocą reseller_table.setItems(data)
, więc nie musisz używać SimpleStringProperty
. Byłoby to przydatne, gdybyś aktualizował tylko jeden wiersz / element. Oto pełny przykład odświeżania danych tabeli:
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Dddeb extends Application {
public static class Product {
private String name;
private String code;
public Product(String name, String code) {
this.name = name;
this.code = code;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
private TableView<Product> productTable = new TableView<Product>();
@Override
public void start(Stage stage) {
Button refreshBtn = new Button("Refresh table");
refreshBtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
// You can get the new data from DB
List<Product> newProducts = new ArrayList<Product>();
newProducts.add(new Product("new product A", "1201"));
newProducts.add(new Product("new product B", "1202"));
newProducts.add(new Product("new product C", "1203"));
newProducts.add(new Product("new product D", "1244"));
productTable.getItems().clear();
productTable.getItems().addAll(newProducts);
//productTable.setItems(FXCollections.observableArrayList(newProducts));
}
});
TableColumn nameCol = new TableColumn("Name");
nameCol.setMinWidth(100);
nameCol.setCellValueFactory(new PropertyValueFactory<Product, String>("name"));
TableColumn codeCol = new TableColumn("Code");
codeCol.setCellValueFactory(new PropertyValueFactory<Product, String>("code"));
productTable.getColumns().addAll(nameCol, codeCol);
productTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
// You can get the data from DB
List<Product> products = new ArrayList<Product>();
products.add(new Product("product A", "0001"));
products.add(new Product("product B", "0002"));
products.add(new Product("product C", "0003"));
//productTable.getItems().addAll(products);
productTable.setItems(FXCollections.observableArrayList(products));
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.getChildren().addAll(productTable, refreshBtn);
Scene scene = new Scene(new Group());
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.setWidth(300);
stage.setHeight(500);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Zauważ, że
productTable.setItems(FXCollections.observableArrayList(newProducts));
I
productTable.getItems().clear();
productTable.getItems().addAll(newProducts);
Są prawie równoważne. Więc użyłem jednego do wypełnienia tabeli po raz pierwszy i inne, gdy stół jest odświeżony. Jest tylko do celów demonstracyjnych. Kod testowałem w JavaFX 2.1. I na koniec możesz (i powinieneś) edytować swoje pytanie, aby go poprawić, przesuwając kawałki kodu w odpowiedzi na pytanie.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:47:07
W końcu znalazłem brzydkie obejście, aby odświeżyć wszystkie wiersze.
void refreshTable() {
final List<Item> items = tableView.getItems();
if( items == null || items.size() == 0) return;
final Item item = tableView.getItems().get(0);
items.remove(0);
Platform.runLater(new Runnable(){
@Override
public void run() {
items.add(0, item);
}
});
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-24 05:51:55
Wydaje się, że istnieje kilka odrębnych kwestii wokół oldItems.equals (newItems)
Pierwsza część RT-22463 : tableView nie zaktualizuje się, nawet jeśli wywoła elementy.clear ()
// refresh table
table.getItems().clear();
table.setItems(listEqualToOld);
To naprawione. Wyczyszczenie starych elementów przed ustawieniem nowej listy czyści cały stary stan, odświeżając w ten sposób tabelę. Każdy przykład, w którym to nie działa, może być regresją.
To, co nadal nie działa, to ponowne ustawianie elementów bez uprzedniego wyczyszczenia
// refresh table
table.setItems(listEqualToOld);
To problem, jeśli tabela pokazuje właściwości, które nie są zaangażowane w równą decyzję elementu (patrz przykład w RT-22463lub Aubin ' s) i pokryte - miejmy nadzieję-przez RT-39094
Aktualizacja: RT-39094 ten ostatni jest również naprawiony, dla 8u40! Powinien bubble się do ea w ciągu kilku tygodni, spekulując na u12 lub takie.
Powodem technicznym wydaje się być sprawdzenie równości w implementacji komórki: sprawdzenie zmian elementu przed faktycznie wywołanie updateItem (t, boolean) zostało wprowadzone w celu rozwiązania problemów z wydajnością. Rozsądne, tylko do twardego kodu "zmiana" = = stare.equals (new) stwarza problemy w niektórych kontekstach.
Obejście, które jest dla mnie w porządku (żadnych formalnych testów! jest to Niestandardowy TableRow, który wskakuje, jeśli wymagane jest sprawdzenie tożsamości:
/**
* Extended TableRow that updates its item if equal but not same.
* Needs custom skin to update cells on invalidation of the
* item property.<p>
*
* Looks ugly, as we have to let super doing its job and then
* re-check the state. No way to hook anywhere else into super
* because all is private. <p>
*
* Super might support a configuration option to check against
* identity vs. against equality.<p>
*
* Note that this is _not_ formally tested! Any execution paths calling
* <code>updateItem(int)</code> other than through
* <code>indexedCell.updateIndex(int)</code> are not handled.
*
* @author Jeanette Winzenburg, Berlin
*/
public class IdentityCheckingTableRow<T> extends TableRow<T> {
@Override
public void updateIndex(int i) {
int oldIndex = getIndex();
T oldItem = getItem();
boolean wasEmpty = isEmpty();
super.updateIndex(i);
updateItemIfNeeded(oldIndex, oldItem, wasEmpty);
}
/**
* Here we try to guess whether super updateIndex didn't update the item if
* it is equal to the old.
*
* Strictly speaking, an implementation detail.
*
* @param oldIndex cell's index before update
* @param oldItem cell's item before update
* @param wasEmpty cell's empty before update
*/
protected void updateItemIfNeeded(int oldIndex, T oldItem, boolean wasEmpty) {
// weed out the obvious
if (oldIndex != getIndex()) return;
if (oldItem == null || getItem() == null) return;
if (wasEmpty != isEmpty()) return;
// here both old and new != null, check whether the item had changed
if (oldItem != getItem()) return;
// unchanged, check if it should have been changed
T listItem = getTableView().getItems().get(getIndex());
// update if not same
if (oldItem != listItem) {
// doesn't help much because itemProperty doesn't fire
// so we need the help of the skin: it must listen
// to invalidation and force an update if
// its super wouldn't get a changeEvent
updateItem(listItem, isEmpty());
}
}
@Override
protected Skin<?> createDefaultSkin() {
return new TableRowSkinX<>(this);
}
public static class TableRowSkinX<T> extends TableRowSkin<T> {
private WeakReference<T> oldItemRef;
private InvalidationListener itemInvalidationListener;
private WeakInvalidationListener weakItemInvalidationListener;
/**
* @param tableRow
*/
public TableRowSkinX(TableRow<T> tableRow) {
super(tableRow);
oldItemRef = new WeakReference<>(tableRow.getItem());
itemInvalidationListener = o -> {
T newItem = ((ObservableValue<T>) o).getValue();
T oldItem = oldItemRef != null ? oldItemRef.get() : null;
oldItemRef = new WeakReference<>(newItem);
if (oldItem != null && newItem != null && oldItem.equals(newItem)) {
forceCellUpdate();
}
};
weakItemInvalidationListener = new WeakInvalidationListener(itemInvalidationListener);
tableRow.itemProperty().addListener(weakItemInvalidationListener);
}
/**
* Try to force cell update for equal (but not same) items.
* C&P'ed code from TableRowSkinBase.
*/
private void forceCellUpdate() {
updateCells = true;
getSkinnable().requestLayout();
// update the index of all children cells (RT-29849).
// Note that we do this after the TableRow item has been updated,
// rather than when the TableRow index has changed (as this will be
// before the row has updated its item). This will result in the
// issue highlighted in RT-33602, where the table cell had the correct
// item whilst the row had the old item.
final int newIndex = getSkinnable().getIndex();
for (int i = 0, max = cells.size(); i < max; i++) {
cells.get(i).updateIndex(newIndex);
}
}
}
@SuppressWarnings("unused")
private static final Logger LOG = Logger
.getLogger(IdentityCheckingListCell.class.getName());
}
// usage
table.setRowFactory(p -> new IdentityCheckingTableRow());
Zauważ, że TableCell ma podobną sprawdzoną równość, więc jeśli Niestandardowy wiersz nie wystarczy, może być konieczne użycie niestandardowej TableCell z podobnym obejściem (haven ' t na przykład, gdzie jest to potrzebne)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-10-24 11:59:41
Przypuszczam, że Ten wątek ma bardzo dobry opis problemu z odświeżaniem tabeli.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-13 01:31:56
Co za robal ! Oto inne obejście...
public void forceRefresh() {
final TableColumn< Prospect, ? > firstColumn = view.getColumns().get( 0 );
firstColumn.setVisible( false );
new Timer().schedule( new TimerTask() { @Override public void run() {
Platform.runLater( new Runnable() { @Override public void run() {
firstColumn.setVisible( true ); }});
}}, 100 );
}
Zrobiłem SSCCE Aby pokazać błąd . Zachęcam wszystkich do poprawienia go w inny bardziej elegancki sposób, ponieważ moje obejście jest bardzo brzydkie!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-27 10:08:16
Mam przypadek użycia, w którym nic innego nie pomogło jako rozwiązanie z Aubin. Dostosowałem metodę i zmieniłem ją, usuwając i dodając element do listy elementów tabel, ponieważ działa w końcu tylko niezawodny z tym włamaniem, kolumna widoczna przełącznik wykonała zadanie tylko za pierwszym razem.
Zgłosiłem to również w zadaniu Jira: https://javafx-jira.kenai.com/browse/RT-22463
public <T> void tableItemsRefresh(final ObservableList<T> items) {
if (items == null || items.size() == 0)
return;
int idx = items.size() -1;
final T item = items.get(idx);
items.remove(idx);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
items.add(item);
}
});
}
}, 100);
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-23 09:23:51
Miałem ten sam problem i po kilku poszukiwaniach to jest moje obejście. Stwierdziłem, że jeśli kolumny zostaną usunięte, a następnie ponownie dodane tabela zostanie zaktualizowana.
public static <T,U> void refreshTableView(final TableView<T> tableView, final List<TableColumn<T,U>> columns, final List<T> rows) {
tableView.getColumns().clear();
tableView.getColumns().addAll(columns);
ObservableList<T> list = FXCollections.observableArrayList(rows);
tableView.setItems(list);
}
Przykład użycia:
refreshTableView(myTableView, Arrays.asList(col1, col2, col3), rows);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-30 00:01:23
Rozwiązanie przez user1236048 jest poprawne, ale kluczowy punkt nie jest wywoływany. W klasach POJO używanych do obserwowalnej listy tabeli, musisz nie tylko ustawić metody getter i setter, ale także nową o nazwie Property. W samouczku Oracle tableview ( http://docs.oracle.com/javafx/2/ui_controls/table-view.htm ), zostawili tę kluczową część!
Oto jak powinna wyglądać Klasa Person:
public static class Person {
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private final SimpleStringProperty email;
private Person(String fName, String lName, String email) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
this.email = new SimpleStringProperty(email);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String fName) {
firstName.set(fName);
}
public SimpleStringProperty firstNameProperty(){
return firstName;
}
public String getLastName() {
return lastName.get();
}
public void setLastName(String fName) {
lastName.set(fName);
}
public SimpleStringProperty lastNameProperty(){
return lastName;
}
public String getEmail() {
return email.get();
}
public void setEmail(String fName) {
email.set(fName);
}
public SimpleStringProperty emailProperty(){
return email;
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-12 22:24:46
Zamiast ręcznego odświeżania należy użyć obserwowalnych właściwości. Odpowiedzi na to pytanie przykładają cel: SimpleStringProperty i SimpleIntegerProperty TableView JavaFX
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:54:37
Na podstawie odpowiedzi Daniela de Leóna
public static void refresh_table(TableView table)
{
for (int i = 0; i < table.getColumns().size(); i++) {
((TableColumn)(table.getColumns().get(i))).setVisible(false);
((TableColumn)(table.getColumns().get(i))).setVisible(true);
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-15 20:51:58
Zobacz ten problem w Jira: https://bugs.openjdk.java.net/browse/JDK-8098085
Komentarz 2012-09-20 08:50 dał obejście, które działa.
//wierd JavaFX bug
reseller_table.setItems(null);
reseller_table.layout();
ObservableList<User> data = FXCollections.observableArrayList(User.getResellers());
reseller_table.setItems(data);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-04 14:46:05
JavaFX8
Dodaję nową pozycję przez okno dialogowe. Oto Mój kod.
ObservableList<Area> area = FXCollections.observableArrayList();
At initialize () lub setApp()
this.areaTable.setItems(getAreaData());
GetAreaData()
private ObservableList<Area> getAreaData() {
try {
area = AreaDAO.searchEmployees(); // To inform ObservableList
return area;
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Error: " + e);
return null;
}
}
Dodaj przez okno dialogowe.
@FXML
private void handleNewArea() {
Area tempArea = new Area();
boolean okClicked = showAreaDialog(tempArea);
if (okClicked) {
addNewArea(tempArea);
this.area.add(tempArea); // To inform ObservableList
}
}
Area
jest zwykłym POJO JavaFX.
Mam nadzieję, że to komuś pomoże.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-02 13:10:05
Metoda Initialize ()
fullNameColumn = new TableColumn("Full name");
fullNameColumn.setCellValueFactory(new PropertyValueFactory<User, String>("fullName"));
usernameColumn = new TableColumn("Username");
usernameColumn.setCellValueFactory(new PropertyValueFactory<User, String>("test"));
emailColumn = new TableColumn("Email");
emailColumn.setCellValueFactory(new PropertyValueFactory<User, String>("email"));
reseller_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
reseller_table.getColumns().addAll(usernameColumn, fullNameColumn, emailColumn);
ObservableList<User> data = FXCollections.observableArrayList(User.getResellers());
reseller_table.setItems(data);
Klasa użytkownika (Klasa Hibernate POJO)
private SimpleStringProperty test;
public void setFullName(String fullName) {
this.fullName = fullName;
this.test = new SimpleStringProperty(fullName);
}
public SimpleStringProperty testProperty() {
return test;
}
Metoda Refresh ()
ObservableList<User> data = FXCollections.observableArrayList(User.getResellers());
reseller_table.setItems(data);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-06-17 12:38:41
Moje rozwiązanie jest podobne do obejścia Daniela de León, ale działa również wtedy, gdy trzeba ukryć pierwszą kolumnę (indeks 0 w jego przykładzie). Oczywiście możesz po prostu zmienić indeks w jego rozwiązaniu, ale jeśli przestawiasz kolumny, moje rozwiązanie może działać lepiej dla Ciebie. Chodzi o to, aby ukryć i pokazać kolumnę po nazwie, zamiast ukrywać i pokazywać ją po indeksie: {]}
private void updateMyTableView() {
// update table view WORKAROUND !!!
if (myTableView != null) {
ObservableList<TableColumn<Entry, ?>> columns = myTableView.getColumns();
for (TableColumn<Entry, ?> column : columns) {
// at this point, we look for the specific column, which should
// always be visible
// therefore we use the "Column Title" String, e.g. "First name"
if (column.getText().equals("Column Title")) {
column.setVisible(false);
column.setVisible(true);
}
}
}
}
Najlepiej zaktualizować tabelę w wątku aktualizacji interfejsu użytkownika. Jednak działa również po prostu wywołując updateMyTableView();
po zmianie czegoś w tabeli, ponieważ JavaFX wydaje się aktualizować w wątku UI i tak (nie jestem tego pewien).
Platform.runLater(new Runnable() {
public void run() {
updateMyTableView();
}
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:26:04
Nie jestem pewien, czy dotyczy to twojej sytuacji, ale opublikuję to, co dla mnie zadziałało.
Zmieniam widok tabeli na podstawie zapytań / wyszukiwań na bazę danych. Na przykład tabela bazy danych zawiera dane pacjenta. Mój początkowy widok tabeli w moim programie zawiera wszystkich pacjentów. Następnie mogę wyszukiwać pacjentów według imienia i nazwiska. Korzystam z wyników tego zapytania, aby ponownie wypełnić moją Obserwowalną listę. Następnie resetuję elementy w widoku tableview wywołując tableview.setItems (observableList):
/**
* Searches the table for an existing Patient.
*/
@FXML
public void handleSearch() {
String fname = this.fNameSearch.getText();
String lname = this.lNameSearch.getText();
LocalDate bdate = this.bDateSearch.getValue();
if (this.nameAndDOBSearch(fname, lname, bdate)) {
this.patientData = this.controller.processNursePatientSearch(fname, lname, bdate);
} else if (this.birthDateSearch(fname, lname, bdate)) {
this.patientData = this.controller.processNursePatientSearch(bdate);
} else if (this.nameSearch(fname, lname, bdate)) {
this.patientData = this.controller.processNursePatientSearch(fname, lname);
}
this.patientTable.setItems(this.patientData);
}
Bloki if aktualizują listę Obserwowalną o wyniki zapytania.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-30 18:06:42
Ten sam problem tutaj, próbowałem kilku rozwiązań i najlepsze dla mnie jest następujące:
W initialize-method kontrolera, Utwórz pustą obserwablelist i ustaw ją do Tabeli:
obsBericht = FXCollections.observableList(new ArrayList<Bericht>(0));
tblBericht.setItems(obsBericht);
W metodzie update, po prostu użyj observableList, wyczyść ją i dodaj odświeżone DANE:
obsBericht.clear();
obsBericht.addAll(FXCollections.observableList(DatabaseHelper.getBerichte()));
// tblBericht.setItems(obsBericht);
Nie jest konieczne ustawianie elementów tabeli ponownie
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-26 12:36:41
Po odpowiedzi Daniela de Leóna ...
- wprowadziłem atrapę właściwości "modelChangedProperty" w moim modelu i
- stworzył metodę refresh () w moim modelu, która zmienia wartość tej właściwości.
- w moim kontrolerze dodałem Listener do atrapy właściwości, która aktualizuje widok tabeli.
-
/**
* Adds a listener to the modelChangedProperty to update the table view
*/
private void createUpdateWorkAroundListener() {
model.modelChangedProperty.addListener(
(ObservableValue<? extends Boolean> arg0, final Boolean oldValue, final Boolean newValue) -> updateTableView()
);
}
/**
* Work around to update table view
*/
private void updateTableView() {
TableColumn<?, ?> firstColumn = scenarioTable.getColumns().get(0);
firstColumn.setVisible(false);
firstColumn.setVisible(true);
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-09 11:40:19
Wiem, że to pytanie ma 4 lata, ale mam ten sam problem, próbowałem rozwiązań z góry i nie zadziałało. Wywołałem również metodę refresh (), ale nadal nie mój oczekiwany wynik. Więc zamieszczam tutaj Moje rozwiązanie może komuś pomoże.
Question db = center.getSelectionModel().getSelectedItem();
new QuestionCrud().deleteQ(db.getId());
ObservableList<Question> aftDelete = FXCollections.observableArrayList(
(new QuestionCrud()).all()
);
center.setItems(aftDelete);
Nawet, że wcześniej używałem innej zmiennej w ObeservableList do ustawiania pozycji w tableview, nazywam to "brudną metodą", ale dopóki nie dostanę lepszego rozwiązania jest ok.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-30 19:38:48
Próbowałem znaleźć sposób na odświeżenie tableView (ScalaFx) przez 3-4 godziny. W końcu dostałem odpowiedź. Chcę tylko opublikować moje rozwiązanie, ponieważ zmarnowałem już godziny.
- Aby pobrać wiersze z bazy danych, użyłem do zadeklarowania metody zwracającej ObservableBuffer.
Moja klasa JDBC
//To get all customer details
def getCustomerDetails : ObservableBuffer[Customer] = {
val customerDetails = new ObservableBuffer[Customer]()
try {
val resultSet = statement.executeQuery("SELECT * FROM MusteriBilgileri")
while (resultSet.next()) {
val musteriId = resultSet.getString("MusteriId")
val musteriIsmi = resultSet.getString("MusteriIsmi")
val urununTakildigiTarih = resultSet.getDate("UrununTakildigiTarih").toString
val bakimTarihi = resultSet.getDate("BakimTarihi").toString
val urununIsmi = resultSet.getString("UrununIsmi")
val telNo = resultSet.getString("TelNo")
val aciklama = resultSet.getString("Aciklama")
customerDetails += new Customer(musteriId,musteriIsmi,urununTakildigiTarih,bakimTarihi,urununIsmi,telNo,aciklama)
}
} catch {
case e => e.printStackTrace
}
customerDetails
}
- i stworzyłem obiekt TableView.
var table = new TableView[Customer](model.getCustomerDetails)
table.columns += (customerIdColumn,customerNameColumn,productInstallColumn,serviceDateColumn,
productNameColumn,phoneNoColumn,detailColumn)
-i w końcu mam rozwiązanie. W przycisku refresh wstawiłem ten kod;
table.setItems(FXCollections.observableArrayList(model.getCustomerDetails.delegate))
Model jest referencją mojej klasy połączeń jdbc
val model = new ScalaJdbcConnectSelect
To kody scalafx, ale daje jakiś pomysł javafx
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-21 15:45:47
Po szukaniu wszystkich możliwych rozwiązań. Najpierw próbowałem wyczyścić dane, a następnie dodałem w tableview tableView.getItems().clear();
nadal to nie rozwiązało mojego problemu. Próbowałem wszystkich odpowiedzi podanych tutaj, ale nie zadziałało dla mnie i nadal miałem stare przedmioty w mojej tabeli, jak pokazano na poniższym obrazku: {]}
Aby to naprawić stworzyłem atrapę etykiety i użyłem setGraphic
w następujący sposób:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-26 21:28:59
我始終認為利用更改TableColumn的visable屬性的方法違反databinding的精神,若這是JavaFX的bug那也早就該接決了,不應該拖到Java8了還不解決。
{[3] }trtrace JavaFX 的 的source code後 ,bbug.利用Listener等方法觀察也沒有異樣也嘗試利用jfacepropopropertychangesupport方式宣告pojo內容變更也沒有效果.最後將DoubleProperty 改為writableobjectvalue,。. 解決於台灣台北
I had firmed use change Column visable Property is not conform data binding Automation purpose.
Po wyśledzeniu kodu źródłowego JavaFX TableView. Nigdy nie odkryłem żadnego problemu z kodowaniem Tableview problem. Po 4 tygodniach temu zmieniłem typ pola POJO z DoubleProperty na Writableobjectvalue, problem został rozwiązany.
resolve in Taiwan Taipei.
Przykładowy kod:
public class CostAnalytics{
protected WritableObjectValue<Double> subtotal=new SimpleObjectProperty<Double>();//利用WritableObjectValue達到自動更新目的,不需要使用個別Column操作setVisable(false)及setVisable(true)
//...
public void setQuantity(double quantity) {
this.pcs.firePropertyChange("quantity", this.quantity, quantity);
this.quantity.set(quantity);
this.calsSubtotal();
}
public WritableObjectValue<Double> getSubtotal() {//利用WritableObjectValue達到自動更新目的,不需要使用個別Column操作setVisable(false)及setVisable(true)
return subtotal;
}
///...
}
TableColumn<CostAnalytics, Double> subtotal = new TableColumn<CostAnalytics, Double>(
"小計");
subtotal.setCellValueFactory(new Callback<CellDataFeatures<CostAnalytics, Double>, ObservableValue<Double>>() {
public ObservableValue<Double> call(
CellDataFeatures<CostAnalytics, Double> p) {
WritableObjectValue<Double> result = p.getValue().getSubtotal();// //利用WritableObjectValue達到自動更新目的,不需要使用個別Column操作setVisable(false)及setVisable(true)
// return (ObservableValue<Double>)
// result;//利用WritableObjectValue達到自動更新目的,不需要使用個別Column操作setVisable(false)及setVisable(true)
// return new
// ReadOnlyObjectWrapper<Double>(p.getValue().getSubtotal());//造成無法自動更新
return (ObservableValue<Double>) p.getValue().getSubtotal();// 利用WritableObjectValue達到自動更新目的,不需要使用個別Column操作setVisable(false)及setVisable(true)
}
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-31 08:35:21