Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Saturday, November 29, 2014

Displaying Elapsed Time with JavaFX 8

In apps like games or training courses, you may want to display an elapsed time that updates with each second.  This post demonstrates a Java SE Timer with a JavaFX app.  A Java 8 Lambda Expression helps to decouple the business logic from the presentation.

Sunday, November 23, 2014

A Deep Copy with Java 8 Streams

map() is a Java 8 Streams method that allows you to apply a function to an object being streamed.  For a deep copy of a Java Collection, you can use a constructor in the map() to return a new object.

Saturday, November 22, 2014

Randomized Lists in Java 8

In a quiz-style game, you may need to create a randomized list of questions.  You can always use Collections.shuffle() to rearrange a java.util.List.  However, if you need to separate the iteration from the List, preserving the original order, you can use Java 8 streams.

Friday, November 21, 2014

A JavaFX Image Map with SceneBuilder

An image map is an image supplemented with hotspots, areas of the screen capable of handling events.  This lets the user interact with a screen using the image as a guide.  Consider a geographical map of the US states where a mouse press allows selection of a state.

In JavaFX, you can create an image map in SceneBuilder using an ImageView containing an Image overlaid with one or more Rectangles.  The Rectangles are transparent, allowing the image to show, and are the receivers of events.

Saturday, November 15, 2014

JavaFX Text Manipulation Functions

I recently coded cut-and-paste functionality into an app.  As a habit, I reached for the Commons Lang StringUtils class to manipulate Strings to extract ranges and to re-form replace text.

There's a simpler way which is to use JavaFX's TextField text manipulation methods.  These methods already work with IndexRange objects, so you don't have to juggle start and end positions.

Thursday, November 13, 2014

JavaFX Dependency Injection with Google Guice

Since introduced into mainstream Java development by the Spring Framework, dependency injection has been an important part of Java EE development.  This blog post shows how to integrate dependency injection into your Java FX app using a super-lightweight container called Google Guice.

Sunday, November 9, 2014

JNLP BasicService, PersistenceService, and Desktop Muffins

Java provides JNLP downloaded desktop applications with a mechanism to record client-side data called "muffins".  Like their web counterparts "cookies", muffins are intended to store small amounts of data to personalize the application.  While the desktop app may prefer to store all information on the server, muffin saving code is orders of magnitude faster than even a speedy web service or RMI call.

Saturday, November 8, 2014

Handling Command Line or JNLP Arguments in Java

If you have a single option that you'd like to pass with your main(), get it using the args String array (arg[0]).  If you have more than one option, consider using the Commons Cli library.  Commons Cli let's you handle any number of options including those with arguments.  Additionally, the command line will be less brittle because order isn't important.

Some Lambda Expressions in JavaFX

If you've coded Objective-C, Dojo, or jQuery projects, you probably passed around blocks of functionality that are executed when an event occurs.  For example, you might pass in a function for updating a webpage to the dojo.xhrPost() call.

Lambda Expressions are a new Java 8 language construct that fosters this pattern of development.  An equivalent to Lambda Expressions -- Anonymous Inner Classes -- has existed for years and is used widely in Swing and Java FX development.  However, the shortened syntax can make a difficult-to-read block of code (loaded with generics, etc) more understandable.

This post presents a few snippets of code showing the new Lambda Expressions in a JavaFX application.

Sunday, November 2, 2014

JavaFX Cut, Copy, and Paste from a ToolBar

Cut, Copy, and Paste work in JavaFX via the key commands without writing code or configuring FXML.  However, applications provide other means to the Clipboard functionality.  In a previous post, I wrote about adding Clipboard functionality to a MenuBar.  This post describes adding the Clipboard operations to a ToolBar.