1

I'm developing a system with the JFoenix library, and I'm using some buttons with wave animation. But when I use a button to open a new window, or load a list for example, the animation "stops" briefly while the screen loads, or the list loads. I would like to know how to run the animation before loading the list, or something like that. Do not let the animation crash. I've tried to use Threads to load the list, however, because the function that calls the thread gets inside the click function of the button, the animation locks in the same way. Another example is when I use a JavaFX transition animation to open a new AnchorPane, while its elements are loading, the animation hangs briefly, and that takes away all the quality of the application

Example, when I click the "add" button shown in the image below, it generates a waveform on the button, then performs a function to open the AnchorPane and a transition function to move the panel to the x = 0 position. And it also carries a simple DropDownList with some elements.

enter image description here

The code executed when the button is clicked:

@FXML
    public void btnAddClique(ActionEvent event) {
        if (telaAtual != 3) { //caso a tela de cadastro nao esteja aberta
            PaneAdd add = new PaneAdd();
            FXMLLoader loader = new FXMLLoader(getClass().getResource("PaneAdd.fxml"));
            loader.setController(add);
            try {
                if (paneAtual == 1) {
                    paneFundo2.getChildren().setAll((Node)loader.load());
                    paneAtual = 2;
                } else {
                    paneFundo.getChildren().setAll((Node)loader.load());
                    paneAtual = 1; 
                }
            } catch (IOException e){
                System.out.println("Erro ao alterar tela, função 'btnAddClique', classe FXMLDocumentController: " + e.toString());
            }
            telaAtual = 3;
            new Thread(new RunAnimacaoAbertura()).start();
            add.init(this.listView);
        }
    }

After that, it runs the Animation Thread:

public class RunAnimacaoAbertura implements Runnable {
        public void run() {
            TranslateTransition tran = new TranslateTransition();
            TranslateTransition tran2 = new TranslateTransition();
            tran.setDuration(Duration.seconds(0.250));
            tran2.setDuration(Duration.seconds(0.250));
            tran.setNode(paneFundo);
            tran2.setNode(paneFundo2);
            if (paneAtual == 1) {
                tran2.setFromX(0);
                tran2.setToX(515);
                tran.setFromX(-515);
                tran.setToX(0);
            } else {
                tran.setFromX(0);
                tran.setToX(515);
                tran2.setFromX(-515);
                tran2.setToX(0);
            }
            tran2.play();
            tran.play();
        }
    }

And finally, it performs the function of loading the list:

public void init(JFXListView<Label> listView) {
        listViewControler = listView;
        cbGerentePA.setItems(arquivo.pegarListaString(1, 0));
        date.setPromptText("Nascimento");
        date.setEditable(false);
        date.setDefaultColor(Color.web("#1abc9c"));
        date.getStylesheets().add("agenda/style.css");
        hBoxFundoDate.getChildren().setAll(date);
    }
  • Can you post some relevant code? It would be easier to understand and help with a concrete scenario. – rmc00 Jun 21 '18 at 18:10
  • Okay, I've already made the changes. – Death Awaits Jun 21 '18 at 18:51
  • 1
    To do something after an `Animation` has finished you can use the [`onFinished`](https://docs.oracle.com/javase/10/docs/api/javafx/animation/Animation.html#onFinishedProperty) property. Is this the kind of thing you're looking for? – Slaw Jun 21 '18 at 18:59
  • 1
    You may want to think about loading your FXML at startup. This will increase the memory footprint of your software though. FXMLLoaders will generally take more time (causing the hang you're noticing) to load an FXML file than it would take to create the JavaFX items in code. So another thing you may want to think about is creating it in code instead of an FXML file. These are the only things I can think of to help you since the thread that's hanging is the JavaFX thread and since the animation starts and then you load, the thread takes the time to load before finishing the animation – Blake Ordway Jun 21 '18 at 19:09
  • Additionally, this post may help: https://stackoverflow.com/a/18710819/9016740 – Blake Ordway Jun 21 '18 at 19:12

0 Answers0