this post was submitted on 12 Jul 2023
3 points (100.0% liked)

JavaFX

119 readers
1 users here now

JavaFX is a software platform and a graphical user interface (GUI) toolkit that allows developers to create rich and interactive applications for desktop, mobile, and embedded devices. It provides a powerful set of tools and APIs for building modern, visually appealing applications.

JavaFX was introduced as a successor to the Swing framework. It is designed to provide a more advanced and flexible way of developing user interfaces compared to Swing, with improved graphics and multimedia capabilities.

Rules

  1. No NSFW/NSFL content
  2. No service requests/offers
  3. Must be JavaFX related
  4. No politics

founded 1 year ago
MODERATORS
 

I'm intimidated by the UI but the allure of cross platform UI draws me in. How does one get started?

you are viewing a single comment's thread
view the rest of the comments
[–] HamsterRage 2 points 1 year ago

The simplest "dead simple" program would be something like this:

public class DeadSimple extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(new Label("Hello World")));
        primaryStage.show();
    }
}

That doesn't include any library management or build stuff, but I created it in a grab-bag project I have for examples and testing out code snippets and it does run.

JavaFX has the idea of a Stage - which corresponds to a Window, and a Scene - which is the wrapper for the content. The Scene contains an object which extends a generic layout class called "Region". In this case, I'm using "Label", which is technically a Region even though you rarely treat it like one.

So this program extends the standard "Application" class, which is the starting point for all JavaFX programs, and implements the "start()" method, which is passed the default Stage. Then it creates a Scene, with a Label as its content and puts it in the Stage. Then "stage.show()" tells it to display it on the screen.

IntelliJ knows enough give me a "Run" option for the class without having to specify a "main()" method.

Everything else follows from there.

Feel free to ask more questions.