Skip to content

Instantly share code, notes, and snippets.

@jewelsea
jewelsea / PannableView.java
Last active July 12, 2021 19:11
Create a pannable map background in JavaFX
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
@jewelsea
jewelsea / package.sh
Last active May 31, 2022 18:24
Shell script to package java code as a native OS X application.
#! /bin/bash
################
# package.sh
#
# Packages java code as a native OS X application
#
# - Fetches source for a Java Swing HelloWorld application from the web
# - Compiles the source
# - Packages the source into a native Mac application
@jewelsea
jewelsea / PromptingTaskDemo.java
Last active April 5, 2023 11:53
Demonstrates a JavaFX task which runs in the background reading data and, when required, pauses from reading data to prompt the user for extra input before continuing processing.
import java.util.concurrent.*;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.application.Platform;
import javafx.beans.property.*;
import javafx.concurrent.Task;
import javafx.event.*;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.*;
@jewelsea
jewelsea / H2Tasks.java
Last active March 5, 2024 22:24
Sample for accessing a local database from JavaFX using concurrent tasks for database operations so that the UI remains responsive.
package h2app;
import javafx.application.Application;
import javafx.collections.*;
import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
@jewelsea
jewelsea / H2app.java
Created February 14, 2013 19:32
Sample for accessing a local database from JavaFX.
import java.sql.*;
import java.util.logging.*;
import javafx.application.Application;
import javafx.collections.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
@jewelsea
jewelsea / FirstLineSequentialVsParallelService.java
Created February 13, 2013 20:29
JavaFX service examples for executing service tasks in parallel or sequentially.
import java.io.*;
import java.net.URL;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import javafx.application.Application;
import javafx.beans.property.*;
import javafx.concurrent.*;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.control.*;
@jewelsea
jewelsea / LineChartWithHover.java
Last active November 11, 2024 20:45
JavaFX sample to display a LineChart which shows the value of a plotted Node when you hover over the Node.
import javafx.application.Application;
import javafx.collections.*;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.chart.*;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
@jewelsea
jewelsea / LoginController.java
Created January 25, 2013 02:47
JavaFX sample for an fxml based Login screen to main application transition with login session data transfer
package login;
import javafx.event.*;
import javafx.fxml.FXML;
import javafx.scene.control.*;
/** Controls the login screen */
public class LoginController {
@FXML private TextField user;
@FXML private TextField password;
@jewelsea
jewelsea / LayerClick.java
Created January 23, 2013 01:50
Demonstrates the JavaFX node mouseTransparent and pickOnBounds properties.
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.value.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;
@jewelsea
jewelsea / MovementEventsDemo.java
Created January 19, 2013 00:31
JavaFX sample of moving a shape around on the screen in response to key and mouse presses.
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.input.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;