Skip to content

Instantly share code, notes, and snippets.

@james-d
james-d / BindingImageSizeDemo.java
Last active August 14, 2023 15:47
Demo of why it is bad to use bindings to make a responsive image container. Here adding padding to the container holding the image (which can be done with an external stylesheet) causes the image to grow indefinitely.
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
@james-d
james-d / Book.fxml
Last active June 27, 2023 19:40
Demo of a MVC-like approach to managing view switching in JavaFX. Contains three views: a login screen, and two other pages. The model holds a user and a "browse state". A view manager determines the current view based on values in the model. The FXML controllers/presenters have a reference to a shared model whose properties they update.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
spacing="20"
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 / 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.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 {
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.function.Function;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
package tankgame;
import java.util.ArrayList;
import java.util.List;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Insets;
@james-d
james-d / FXCamTest.java
Last active May 18, 2018 16:11
JavaFX wrapper classes for sarxos webcam Java library. Wraps a web cam as a JavaFX Service and provides a View class for the service.
import com.github.sarxos.webcam.Webcam;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.animation.Animation;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.SequentialTransition;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.HPos;
import javafx.scene.Node;
<!-- in arrival package -->
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>