Cold cup of Java
Cold cup of Java

Reputation: 27

Converting a simple Applet GUI from Swing to JavaFX

I am trying to create an applet that will replace a confusing CLI with a nice JavaFX GUI. I don't have extensive experience with GUI design and most of what we learned in the classroom environment was Swing/AWT. Having toyed a little bit with JavaFX, I feel that it has already shown to be far better, however there aren't many good tutorials/articles out there about creating JavaFX programs intended to run as applets. Right now I can't even seem to convert the following simple login UI from Swing to JavaFX.

import java.applet.Applet;
import java.awt.*;
import javax.swing.*;


public class ACLEditor extends Applet {

    public void init() {

        /* Basic Layout */
        setLayout(new GridLayout(5, 2));

        /* Components */
        JLabel username_l = new JLabel("Username:");
        JTextField username = new JTextField("", 10);
        JLabel password_l = new JLabel("Password:");
        JPasswordField password = new JPasswordField("", 10);
        JLabel hostname_l = new JLabel("Hostname:");
        JTextField hostname = new JTextField("0.0.0.0", 10);

        JButton connect_btn = new JButton("Connect");

        /* Place all Controls on the Layout */
        add(username_l);
        add(username);
        add(password_l);
        add(password);
        add(hostname_l);
        add(hostname);
        add(connect_btn);

    }


}

Any help on this would be appreciated. Note: I do understand how to create a JavaFX UI for a standalone application, I just can't seem to grasp how to make it into an applet

Upvotes: 1

Views: 2149

Answers (2)

jewelsea
jewelsea

Reputation: 159386

As of JavaFX 8, you can deploy a JavaFX app in some desktop browsers using the JavaFX packaging tools and deployment toolkit. There are caveats regarding this approach. A brief description of some of these and summary of how to deploy is in: JavaFX - can it really be deployed in a browser?.

You don't need a JFXPanel to achieve this and I wouldn't recommend one unless your app also used Swing controls.

Upvotes: 1

Cold cup of Java
Cold cup of Java

Reputation: 27

After looking around more, it seems the best way to incorporate JavaFX elements into a project that uses Swing UI architecture (like my little applet) is to place those elements on a JFXPanel.

http://docs.oracle.com/javafx/2/api/javafx/embed/swing/JFXPanel.html

This will allow the applet to be deployed in the same fashion as it was originally, while also adding nice looking JavaFX components to the GUI.

Upvotes: 0

Related Questions