Skip to content

Instantly share code, notes, and snippets.

james-d

Block or report user

Report or block james-d

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@james-d
james-d / ListCellTaskExample.java
Last active Oct 14, 2019
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.
View ListCellTaskExample.java
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 / EditCell.java
Created Feb 13, 2015
(Fairly) reusable edit cell that commits on loss of focus on the text field. Overriding the commitEdit(...) method is difficult to do without relying on knowing the default implementation, which I had to do here. The test code includes a key handler on the table that initiates editing on a key press.
View EditCell.java
import javafx.event.Event;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
View HighlightingLabelLayout.java
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 / AnimationTimerTest.java
Last active Sep 13, 2019
Experiment to see how smooth animation is in JavaFX using an AnimationTimer to update the view on each pulse. This simulates 300 balls of various sizes bouncing (with perfect elasticity) off each other and the edges of the Pane in which they're contained. It could easily be extended to a simulation where the pressure on each wall was measured by…
View AnimationTimerTest.java
import static java.lang.Math.PI;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.sqrt;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.BLUE;
import static javafx.scene.paint.Color.BROWN;
import static javafx.scene.paint.Color.GREEN;
import static javafx.scene.paint.Color.PINK;
import static javafx.scene.paint.Color.RED;
@james-d
james-d / CalendarView.java
Last active Sep 1, 2019
Simple demo of creating a appointment-calendar like view (similar to the default calendar view in Google Calendar), in JavaFX 8. Just manages selection of time slots in the grid.
View CalendarView.java
package calendarview;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@james-d
james-d / Investigator.java
Created May 11, 2014
Example of JPA entities that use JavaFX properties. These use a "super-lazy" idiom for instantiating the properties, and implement Externalizable to work around the lack of Serialization support in the FX property classes.
View Investigator.java
package edu.marshall.genomics.lims.entities;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
@james-d
james-d / PlutoExplorer.java
Last active May 8, 2019
Zoomable and Pannable JavaFX ImageView Example
View PlutoExplorer.java
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
@james-d
james-d / ShootingGame.java
Last active Apr 28, 2019
Demo of using Shape.intersect(...) in conjunction with a TranslateTransition to test for collisions.
View ShootingGame.java
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 / TableViewSample.java
Created Dec 2, 2013
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.)
View TableViewSample.java
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 / ZoomableLineChart.java
Created Oct 31, 2013
Example of a LineChart that can be zoomed via mouse.
View ZoomableLineChart.java
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;
You can’t perform that action at this time.