Skip to content

Instantly share code, notes, and snippets.

@james-d
james-d / Clock.java
Last active August 29, 2015 13:57
Java 8 Clock with convenient string bindings for "xxx ago" labels, with an example.
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import javafx.application.Application;
import javafx.beans.property.FloatProperty;
import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleStringProperty;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javafx.application.Application;
import javafx.beans.Observable;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import javafx.animation.PauseTransition;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
@james-d
james-d / JavaBeanPropertyAdapterTest.java
Last active August 29, 2015 14:17
Demo of JavaBeanPropertyAdapter
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.property.StringProperty;
@james-d
james-d / AdditionTest.java
Last active August 29, 2015 14:18
Simple instructional example for the basics of using event-driven programming. In real life, I would improve this code with lots of binding.
import java.util.Random;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
@james-d
james-d / TableViewSingleClickEditTest.java
Created April 17, 2015 19:47
Beginnings of a TableView example that has a more "spreadsheet-like" editing facility. Not intended to be production code, but demonstrates some ideas.
import java.util.function.Function;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
@james-d
james-d / WebBrowserMultipleLoadingTest.java
Last active August 29, 2015 14:19
Loading multiple web pages
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebBrowserMultipleLoadingTest extends Application {
@Override
public void start(Stage primaryStage) {
@james-d
james-d / PopupFromBackgroundThreadDemo.java
Last active August 29, 2015 14:20
Simple example showing a popup shown from a background thread (simulating receiving messages from a server...). (No fancy UI, just showing the idea).
import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
@james-d
james-d / BoundTableColumnHeader.java
Created May 15, 2015 17:39
Binding a table column header text to a combo box.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;