0

I have a problem with my programmcode! I want to use a AnchorPane, which is created by a FXML Document. The AnchorPane will initialize by the controller in the initialize method!

Here's some Code of my Programm, which includes the errors:

import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

public class MenuFXMLController implements Initializable{

    @FXML
    public AnchorPane INSTALLED_PANE, DOWNLOAD_PANE;

    public static AnchorPane STATIC_PANE_INSTALLED, STATIC_PANE_DOWNLOAD;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        MenuFXMLController.STATIC_PANE_INSTALLED = INSTALLED_PANE;
        MenuFXMLController.STATIC_PANE_DOWNLOAD = DOWNLOAD_PANE;


        System.out.println("Menu Controller initialized!");
    }

}
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import schnartzke.luca.engine.gui.controller.MenuFXMLController;

public class AddonShowcase {

    public static ArrayList<AddonShowcase> addonshowcaseList = new ArrayList<>();

    private String name;
    private BufferedImage img;

    public AddonShowcase(String name, BufferedImage img){
        this.name = name;
        this.img = img;
    }

    public Pane getShowCasePane(){
        try {
            Pane pa = new Pane();
            pa.setPrefSize(100, 80);
            Image image = SwingFXUtils.toFXImage(img, null);
            ImageView iv = new ImageView(image);
            iv.setFitWidth(100);
            iv.setFitWidth(40);
            iv.setX(0);
            iv.setY(20);
            pa.getChildren().add(iv);
            Text txt = new Text(name);
            txt.setX(0);
            txt.setY(0);
            txt.setFont(new Font("Arial", 12));
            pa.getChildren().add(txt);
            return pa;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    public static void printAddonShowcaseListToDownloadAddonsPane(){
        AnchorPane ap = MenuFXMLController.STATIC_PANE_DOWNLOAD;

        for(int i = 0; i < addonshowcaseList.size(); i++){
            Pane p = addonshowcaseList.get(i).getShowCasePane();

            p.setLayoutX(i * 110);
            Text txt = new Text(100, 100, "Test Text fick mich AMK");
            txt.setFont(new Font("arial", 20));
            //ap.getChildren().add(p);
            ap.getChildren().add(txt);
        }

    }

}

Stack Trace:

java.lang.IllegalStateException: Not on FX application thread; currentThread = pool-2-thread-1
    at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:279)
    at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
    at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
    at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:206)
    at package.AddonShowcase.printAddonShowcaseListToDownloadAddonsPane(AddonShowcase.java:63)
    at package.AuthentifikationSystem$InputCheckService.run(AuthentifikationSystem.java:216)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Slaw
  • 25,955
  • 5
  • 33
  • 58
  • That class has to extend `javafx.application.Application`. – Sedrick Jun 09 '19 at 15:41
  • Take some time to do some JavaFX tutorials. Take some time and learn about Java's best coding practices. Just looking at your code, I can tell you have done neither. [Tutorials](https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm). [Naming convention](https://en.wikipedia.org/wiki/Naming_convention_(programming)#Java). – Sedrick Jun 09 '19 at 15:47

0 Answers0