Skip to content

Instantly share code, notes, and snippets.

@james-d
james-d / application.css
Last active May 14, 2023 10:58
Example of using Bindings (extensively) for validation in JavaFX. Maybe a basis for thinking about a validation framework.
.root {
error-color: #ffa0a0 ;
}
.text-field:validation-error {
-fx-background-color: error-color ;
}
.label.error-instructions {
-fx-text-fill: error-color ;
}
@james-d
james-d / AnimatedPropertiesTest.java
Created January 17, 2014 15:08
Some simple examples of animations with a Button
import java.util.concurrent.Callable;
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.RotateTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
@james-d
james-d / TableWithSelectBinding.java
Last active December 6, 2022 08:15
The Bindings.select*(...) family of methods use try-catch to implement null checking of "intermediate" properties. This is highly inefficient, as demonstrated by this example. Sort by the "Zip" column to see the problem.
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
package org.jamesd.examples.trajectories;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.layout.BorderPane;
@james-d
james-d / ZoomableLineChart.java
Created October 31, 2013 16:29
Example of a LineChart that can be zoomed via mouse.
import java.util.Collections;
import java.util.Random;
import javafx.application.Application;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.util.stream.Collectors;
import javafx.beans.property.StringProperty;
import javafx.beans.property.StringPropertyBase;
import javafx.css.PseudoClass;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
public class HighlightingLabelLayout extends Pane {
@james-d
james-d / CovidCases.java
Last active February 11, 2022 04:33
Covid count viewer by county and date in the US. Mostly an experiment to test JavaFX TableView performance.
package org.james_d.examples.covidcases;
import com.opencsv.CSVReader;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.util.Random;
import java.util.function.Function;
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
@james-d
james-d / CalendarView.java
Last active November 16, 2021 19:49
Simple example of a calendar display. Supports some basic CSS styling and direct localization (in practice you would almost never need localization, just use the default locale; but it was fun to play with). Includes a simple example.
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
import java.util.Locale;
import javafx.beans.binding.Bindings;
@james-d
james-d / MockServer.java
Created February 18, 2016 14:15
Example of showing an alert from background thread using `Platform.runLater(...)`
import static javafx.beans.binding.Bindings.when;
import java.util.Random;
import java.util.function.Consumer;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Service;
import javafx.concurrent.Task;