JavaFX Platform set label text from Swing component

Description

JavaFX Platform set label text from Swing component

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javafx.application.Platform;


public class Main extends JFrame{
    //from   w  ww  . j  a  va2 s. c o m
    JLabel formTitle, first, last, buttonLbl;
    protected JTextField firstField, lastField;
    
    public Main(){

    JPanel innerPanel = new JPanel();
    
    GridLayout gl = new GridLayout(3,2);
    innerPanel.setLayout(gl);
    
    first = new JLabel("First Name:");
    innerPanel.add(first);
    firstField = new JTextField(10);
    innerPanel.add(firstField);

    last = new JLabel("Last Name:");
    innerPanel.add(last);
    lastField = new JTextField(10);
    innerPanel.add(lastField);
    
    JButton button = new JButton("Submit");
    button.addActionListener((event) -> {
        Platform.runLater(()-> {
            //YourJavaFXForm.fxLabel.setText("Message from Swing form...");
        });
    });
    buttonLbl = new JLabel("Click Me:");
    innerPanel.add(buttonLbl);
    innerPanel.add(button);
    add(innerPanel);

    }
}



PreviousNext

Related