DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • How Agile Works at Tesla [Video]
  • Knowing and Valuing Apache Kafka’s ISR (In-Sync Replicas)
  • Using OpenAI Embeddings Search With SingleStoreDB
  • Database Integration Tests With Spring Boot and Testcontainers

Trending

  • How Agile Works at Tesla [Video]
  • Knowing and Valuing Apache Kafka’s ISR (In-Sync Replicas)
  • Using OpenAI Embeddings Search With SingleStoreDB
  • Database Integration Tests With Spring Boot and Testcontainers
  1. DZone
  2. Coding
  3. Java
  4. JavaFX FXML Meets the NetBeans Platform

JavaFX FXML Meets the NetBeans Platform

Geertjan Wielenga user avatar by
Geertjan Wielenga
·
Apr. 14, 13 · Interview
Like (0)
Save
Tweet
Share
9.00K Views

Join the DZone community and get the full member experience.

Join For Free

Here's the FXML that we'd like to see in a NetBeans Platform TopComponent:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<BorderPane id="topNode" xmlns:fx="http://javafx.com/fxml"
            fx:controller="org.nb.demo.DemoController">    
    <top>
        <HBox fx:id="topHBox" spacing="10">
                <Label fx:id="myLabel1"
                       textFill="#0076a3"            
                       style="-fx-font: Bold 20 papyrus"/>
                <Label fx:id="myLabel2"
                       textFill="#0076a3"
                       wrapText="true"/>
        </HBox>       
        
    </top>
                     
</BorderPane>

Binding will happen on "fx:id" so "myLabel1" and "myLabel2" will be bound to labels named "myLabel1" and "myLabel2". Here's the related controller, in package "org.nb.demo", as specified in the "fx:controller" attribute above:

package org.nb.demo;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;

public class DemoController implements Initializable {

    @FXML
    private Label myLabel1;
    @FXML
    private Label myLabel2;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        myLabel1.setText("hello");
        myLabel2.setText("world");
    }

}

And, finally, here's how to call the above from a TopComponent:

...
...
...
public final class DemoTopComponent extends TopComponent {

    private DemoController controller;
    private JFXPanel fxPanel;

    public DemoTopComponent() {
        initComponents();
        setName(Bundle.CTL_DemoTopComponent());
        setToolTipText(Bundle.HINT_DemoTopComponent());
        setLayout(new BorderLayout());
        init();
    }

    public void init() {
        fxPanel = new JFXPanel();
        add(fxPanel, BorderLayout.CENTER);
        Platform.setImplicitExit(false);
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                createScene();
            }
        });
    }

    private void createScene() {
        try {
            URL location = getClass().getResource("Demo.fxml");
            FXMLLoader fxmlLoader = new FXMLLoader();
            fxmlLoader.setLocation(location);
            fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
            Parent root = (Parent) fxmlLoader.load(location.openStream());
            Scene scene = new Scene(root);
            fxPanel.setScene(scene);
            controller = (DemoController) fxmlLoader.getController();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
...
...
...

Result:

NetBeans JavaFX

Opinions expressed by DZone contributors are their own.

Trending

  • How Agile Works at Tesla [Video]
  • Knowing and Valuing Apache Kafka’s ISR (In-Sync Replicas)
  • Using OpenAI Embeddings Search With SingleStoreDB
  • Database Integration Tests With Spring Boot and Testcontainers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: