Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7713161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:48:12+00:00 2026-06-01T01:48:12+00:00

Overview As a Swing developer of ten years, I’ve been thrilled with the features

  • 0

Overview

As a Swing developer of ten years, I’ve been thrilled with the features introduced with JavaFX 2.0, especially the rich, fluent, high-level data-binding facilities. This facility alone is worth the cost of learning a new API (which is much less since abandoning FX script). It’s going to have a direct impact on the readability and maintainably of my model/view synchronization code.

So far I’m having great success at first level and basic derived bindings, but am struggling to figure out the “JavaFX way” of binding one value to a value two or more levels of indirection in the data graph.

Problem

As shown in the code example below, I’m attempting to use javafx.beans.binding.Bindings.select() to synchronize the text value of a Label with one of the contained properties of the currently selected item in a ComboBox. This code is a simple example of something more complex I’m trying to do, so I understand that it’s not hard to do this with the lower level bindings API. I’d like to know if it’s possible with the higher-level fluent API, and if the select(...) method actually tracks changes in the indirect properties (i.e. update property if either the direct property or the selected subproperty change).

The documentation and examples on select(...) are sparse, so I’m hoping someone with advanced experience with this can tell me if I’m trying to use the API as designed, or if there’s another way to use the high-level binding API to do what I want.

Sample Code

Here’s the demo code. When run, there’s a ComboBox with two items in it, and then two labels. The first label shows the toString() version of the selected item. The second label attempts to display one of the properties of the selected item, but only displays null.

import static javafx.beans.binding.Bindings.*;
import javafx.application.Application;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/** Testing cascading binding change triggers. */
public class SandboxTest extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {

        VBox root = new VBox(8);
        root.setStyle("-fx-padding: 8;");
        Scene s = new Scene(root);

        stage.setWidth(200);
        stage.setScene(s);

        ComboBox<MoPoJo> list = new ComboBox<SandboxTest.MoPoJo>();

        list.itemsProperty().set(FXCollections.observableArrayList(new MoPoJo("foo", "bar"), new MoPoJo("baz", "bat")));

        Label direct = new Label();
        direct.setTooltip(new Tooltip("Selected item to string"));
        Label withSelect = new Label();
        withSelect.setTooltip(new Tooltip("Second property of selected item"));

        direct.textProperty().bind(convert(list.getSelectionModel().selectedItemProperty()));
        withSelect.textProperty().bind(convert(select(list.getSelectionModel().selectedItemProperty(), "two")));

        root.getChildren().addAll(list, direct, withSelect);
        stage.show();
    }

    private static class MoPoJo {
        private StringProperty _one = new SimpleStringProperty();
        private StringProperty _two = new SimpleStringProperty();
        private StringProperty _name = new SimpleStringProperty();

        public MoPoJo(String o, String t) {
            _one.set(o);
            _two.set(t);
            _name.bind(format("{ %s, %s }", oneProperty(), twoProperty()));
        }

        public StringProperty oneProperty() {
            return _one;
        }

        public StringProperty twoProperty() {
            return _two;
        }

        public ReadOnlyStringProperty nameProperty() {
            return _name;
        }

        @Override
        public String toString() {
            return nameProperty().get();
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:48:13+00:00Added an answer on June 1, 2026 at 1:48 am

    Bindings.select can’t access private class. Make MoPoJo a public class and your code will work.

    public static class MoPoJo {
    

    P.S: I believe that fact worth to be mentioned in docs, so I filed http://javafx-jira.kenai.com/browse/RT-20640 on JavaFX javadoc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading the javadocs trying to grasp around the swing Document API but
Overview I'm working on an iPhone game whose code I inherited from another developer.
Overview of the problem: I've been playing with writing custom http server apps for
can someone give me a high level overview of what the differences are? why
Overview I am using CompositeWPF to create an app using C#. This really should
Overview I am trying to get a photo feed on to my site using
Overview I have an iOS project which contains 2 navigation controllers as shown in
Overview: Trying to write a trigger for a SQL Server 2008 database. TableA and
Overview I'm looking for advice / solutions on standardizing color profiles on comps so
Overview The background color of my iPhone app in the simulator (iMac) looks different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.