简体   繁体   中英

Add a panel to a fxml pane

I am new to JavaFX and I am trying to do an app that will show several panels from the same class: The class PacienteGUI creates a panel, and I want to show 5 of this PacienteGUI panels in my main FXML, which has a panel itself. I´ve tried to add it through the controller by

@FXML Pane principal;

@Override
public void initialize(URL url, ResourceBundle rb) 
{
    PacienteGUI paciente = new PacienteGUI(1);
    principal.getChildren().add(paciente);
} 

Part of the PacienteGUI:

public class PacienteGUI extends javax.swing.JPanel {

public PacienteGUI(int num) {
    chairNum = num;
    initComponents();
}

private void initComponents() {
..
..
..Creates JPanel with all its components
..
}

The problem is that it says that PacientesGUI cannot be converted to node. How can I solve this??

Thanks

Your Paciente class is a Swing JPanel , which cannot be placed in a JavaFX Pane directly.

You either need to make Paciente a subclass of a JavaFX Pane , or you need to wrap the Paciente instance in a SwingNode . The latter ( SwingNode ) is tricky, because you will need to use two different threads to create the different components: swing components need to be created and accessed on the AWT event dispatching thread, and JavaFX components need to be created on the FX Application Thread. I strongly recommend not mixing JavaFX and Swing if you can do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM