The Artima Developer Community
Sponsored Link

Java Buzz Forum
Read-only properties in JavaFX 8

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
News Manager

Posts: 47623
Nickname: newsman
Registered: Apr, 2003

News Manager is the force behind the news at Artima.com.
Read-only properties in JavaFX 8 Posted: Oct 20, 2016 12:44 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by News Manager.
Original Post: Read-only properties in JavaFX 8
Feed Title: JavaWorld
Feed URL: http://www.javaworld.com/index.rss
Feed Description: JavaWorld.com: Fueling Innovation
Latest Java Buzz Posts
Latest Java Buzz Posts by News Manager
Latest Posts From JavaWorld

Advertisement

You're building a JavaFX library with properties that must appear read-only to external clients while remaining updatable to library code. How do you accomplish this duality? This post presents JavaFX 8's answer to this question.

The need for read-only exposure

Before I show you how to create updatable properties that are read-only to external clients, let's review how to define a simple property. Listing 1 presents the source code to a class that implements a counter property.

Listing 1. Implementing a counter property

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

public final class Counter
{
   private IntegerProperty counter = new SimpleIntegerProperty();

   public IntegerProperty counterProperty()
   {
      return counter;
   }

   public int getCounter() 
   {
      return counter.get();
   }

   public void increment()
   {
      counter.set(counter.get() + 1);
   }
}

Counter first introduces a javafx.beans.property.IntegerProperty field that defines a counter property wrapping a 32-bit integer value. Because IntegerProperty is abstract, I initialize this field to an instance of the concrete javafx.beans.property.SimpleIntegerProperty class, which implements the property. Furthermore, its noargument constructor initializes the property value to 0.

To read this article in full or to leave a comment, please click here

Read: Read-only properties in JavaFX 8

Topic: Neo4j: Detecting rogue spaces in CSV headers with LOAD CSV Previous Topic   Next Topic Topic: Ultimate Guide to Reducing the Amount of Defects and other Waste in your Product

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use