Skip to content

Instantly share code, notes, and snippets.

@james-d
james-d / PanningTiledPane.java
Last active July 16, 2018 23:36
Example of (essentially) infinite panning in JavaFX using a fixed set of ImageViews and updating their images on panning. Prototype for Google Maps type of interface.
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.DoublePropertyBase;
import javafx.beans.property.ReadOnlyIntegerWrapper;
import javafx.geometry.Pos;
@james-d
james-d / SunEarthMoon.java
Last active May 18, 2018 16:16
Very simple (and not intended to be accurate) model of the sun, earth and moon to demonstrate rotations applied to circles in JavaFX.
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
@james-d
james-d / UndoRectangle.java
Last active May 25, 2016 23:41
Experiment with UndoFX and dragging to move/resize a rectangle. Requires [UndoFX](https://github.com/TomasMikula/UndoFX/)
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import org.fxmisc.undo.UndoManager;
import org.fxmisc.undo.UndoManagerFactory;
import org.reactfx.EventStream;
import org.reactfx.EventStreams;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class CyrillicAndLatin extends Application {
@james-d
james-d / LabelsWithStrikethrough.java
Created March 22, 2016 16:43
Demo of using CSS pseudoclasses to provide strikethrough in labels
import java.util.Arrays;
import java.util.List;
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.css.PseudoClass;
import javafx.scene.Scene;
import javafx.scene.control.Button;
@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;
@james-d
james-d / RectangleDrawing.java
Last active June 27, 2023 19:50
Demo of event handling and consuming events. Double click to add a rectangle. Selected rectangles have a gold border. Drag a rectangle to move it; drag on empty space to select.
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener.Change;
@james-d
james-d / ScoreTable.java
Created January 27, 2016 23:50
Example of table with varying number of columns according to user input
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.IntegerBinding;
import javafx.beans.binding.ObjectBinding;
import javafx.collections.FXCollections;
package hangman;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.scene.Scene;
import javafx.scene.control.Button;
@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;