Skip to content

Instantly share code, notes, and snippets.

@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;
@james-d
james-d / ComboBoxSortableTable.java
Last active June 1, 2018 15:13
TableView that sorts either by clicking on the column headers or by selecting a column from a combo box.
import java.util.Arrays;
import java.util.Collections;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
@james-d
james-d / PseudoClassExample.java
Last active December 28, 2015 19:19
Example of using new Pseudoclass API in JavaFX 8.
package pseudoclasstest;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import java.util.Arrays;
import java.util.List;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.beans.property.SimpleDoubleProperty;
@james-d
james-d / ListCellTaskExample.java
Last active October 20, 2020 13:27
Example of a ListView which displays tasks. The customized ListCell updates its display depending on the state and progress of the task. The Task implementation introduces a counter property: since changing the value of this property will result in changes to the UI, these changes must be performed on the FX Application Thread.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ReadOnlyIntegerProperty;
import javafx.beans.property.ReadOnlyIntegerWrapper;
import javafx.beans.value.ChangeListener;
@james-d
james-d / TableViewSample.java
Created December 2, 2013 21:02
TableView with context menu applied to table rows. Based on the example in the tutorial at http://docs.oracle.com/javafx/2/ui_controls/table-view.htm#CJAGAAEE. (I don't necessarily like the style of some of this, but wanted to keep changes to the standard example minimal.)
import java.util.Arrays;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
@james-d
james-d / HighlightingTableViewSample.java
Last active May 22, 2021 14:31
Example of a row factory wrapper for TableViews which manages adding and removing a style class from a list of row indexes.
import java.util.Arrays;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
@james-d
james-d / HighlightingTableViewSample.java
Last active January 18, 2016 22:37
JavaFX 8 version of https://gist.github.com/james-d/7813134, taking advantage of pseudoclasses.
import java.util.Arrays;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
@james-d
james-d / ShootingGame.java
Last active March 26, 2021 23:15
Demo of using Shape.intersect(...) in conjunction with a TranslateTransition to test for collisions.
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
@james-d
james-d / Person.java
Last active October 2, 2020 07:15
Example of attaching context-specific context menus to a TableView. Menus are attached for the TableView context, TableRow context, and TableCell context.
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Person {
private final StringProperty firstName ;
private final StringProperty lastName ;
private final StringProperty email ;
public Person(String firstName, String lastName, String email) {
this.firstName = new SimpleStringProperty(this, "firstName", firstName);