io.github.dinamo541.corefx.ui

TableUtils

Static utilityUtilidad estática final JavaFX

Type-safe, lambda-first helpers for TableView. Build columns from extractor functions (no stringly-typed property names), populate and select rows, set placeholders, and install a ready-made live search filter that coexists with the table's own column sorting. Ayudantes con tipos seguros y orientados a lambdas para TableView. Construye columnas a partir de funciones extractoras (sin nombres de propiedad como cadenas), puebla y selecciona filas, fija placeholders e instala un filtro de búsqueda en vivo listo para usar que convive con el propio ordenamiento por columnas de la tabla.

Why lambda columnsPor qué columnas con lambdas

The classic PropertyValueFactory("name") is reflection-based and fails silently at runtime if the property name is wrong. TableUtils.createColumn(title, Person::getName) is checked at compile time and refactor-safe. The PropertyValueFactory path is still offered for JavaBean models that need it. El clásico PropertyValueFactory("name") se basa en reflexión y falla en silencio en tiempo de ejecución si el nombre de la propiedad es incorrecto. TableUtils.createColumn(title, Person::getName) se comprueba en tiempo de compilación y es seguro ante refactorizaciones. La vía de PropertyValueFactory se sigue ofreciendo para modelos JavaBean que la necesiten.

Quick startInicio rápido

// Columns from method references — type-safe:
TableUtils.addColumn(table, "Name",  Person::getName);
TableUtils.addColumn(table, "Email", Person::getEmail);

// Populate and get the backing observable list:
ObservableList<Person> data = TableUtils.setItems(table, people);
TableUtils.setPlaceholder(table, "No people yet");

// Live search bound to a text field (filtering + sorting coexist):
TableUtils.installFilter(table, data, searchField,
        (person, query) -> person.getName().toLowerCase().contains(query.toLowerCase()));

Column creationCreación de columnas

static <S,T> TableColumn<S,T> createColumn(String title, Function<S,T> extractor)

A column whose value is derived from each row by extractor. Type-safe, naming-independent. Both args non-null.Una columna cuyo valor se deriva de cada fila mediante extractor. Con tipos seguros e independiente de nombres. Ambos argumentos no null.

static <S,T> TableColumn<S,T> createPropertyColumn(String title, String propertyName)

A column bound to a JavaBean property by name (via PropertyValueFactory). propertyName must be non-blank. Prefer createColumn for compile-time safety.Una columna ligada a una propiedad JavaBean por nombre (vía PropertyValueFactory). propertyName no puede estar en blanco. Prefiere createColumn por la seguridad en compilación.

static <S,T> TableColumn<S,T> addColumn(TableView<S> table, String title, Function<S,T> extractor)

Creates a column with createColumn and appends it to the table, returning it.Crea una columna con createColumn y la añade a la tabla, devolviéndola.

Items & placeholderItems y placeholder

static <S> ObservableList<S> setItems(TableView<S> table, Collection<S> items)

Replaces the table's items, returning the new backing ObservableList. A null collection clears the table.Reemplaza los items de la tabla, devolviendo la nueva ObservableList de respaldo. Una colección null vacía la tabla.

static <S> void setPlaceholder(TableView<S> table, String text)

Text shown when there are no visible rows. null shows no placeholder.Texto mostrado cuando no hay filas visibles. null no muestra placeholder.

SelectionSelección

MethodMétodoReturns / behaviourDevuelve / comportamiento
enableMultiSelection(table)Switches to multiple-row selection.Cambia a selección de múltiples filas.
getSelectedItem(table)The selected row, or null.La fila seleccionada, o null.
getSelectedItems(table)An unmodifiable snapshot of all selected rows.Una instantánea no modificable de todas las filas seleccionadas.
clearSelection(table)Clears the selection.Limpia la selección.
selectFirst(table)Selects the first row if any exist.Selecciona la primera fila si existe alguna.

Live search filterFiltro de búsqueda en vivo

static <S> FilteredList<S> installFilter(TableView<S> table, ObservableList<S> source, TextField searchField, BiPredicate<S,String> matcher)

Narrows the table as the user types. The source is wrapped in a FilteredList (for matching) and a SortedList whose comparator is bound to the table — so filtering and column sorting coexist. An empty query shows all rows. Returns the FilteredList for further tuning. All four args non-null.Acota la tabla a medida que el usuario escribe. La fuente se envuelve en una FilteredList (para coincidencias) y una SortedList cuyo comparador se liga a la tabla — así el filtrado y el ordenamiento por columnas conviven. Una consulta vacía muestra todas las filas. Devuelve la FilteredList para ajustes adicionales. Los cuatro argumentos no null.

🛡️
A faulty matcher can't break the tableUn matcher defectuoso no puede romper la tabla

The matcher receives each row and the trimmed query. Any exception it throws is treated as "no match", so a buggy predicate degrades gracefully instead of crashing the UI.El matcher recibe cada fila y la consulta recortada. Cualquier excepción que lance se trata como "sin coincidencia", así un predicado con bugs degrada con elegancia en vez de tirar la UI.

⚠️
installFilter replaces the table's itemsinstallFilter reemplaza los items de la tabla

It calls table.setItems(sortedList) internally. Keep your original source list to mutate the data; don't also call setItems with a different list afterwards, or you'll detach the filter.Llama internamente a table.setItems(sortedList). Conserva tu lista source original para mutar los datos; no llames además a setItems con otra lista después, o desacoplarás el filtro.

RecommendationsRecomendaciones

Prefer createColumn/addColumn with method references over property-name columns.Prefiere createColumn/addColumn con referencias a métodos sobre las columnas por nombre de propiedad.

Keep the ObservableList returned by setItems — add/remove on it and the table (and any installed filter) update live.Conserva la ObservableList que devuelve setItems — añade/elimina en ella y la tabla (y cualquier filtro instalado) se actualizan en vivo.