0

I have an multi-window javafx mailbox project.Which is realized by turning the visibility and availability true and false of the window(anchorpane). now I hava two windows (paneA and B),When i switch from A to B,because there is a process where i need to load some information into the pane B and which would take some time, I wanted to make an progressindicator to show that panel B is actually loading information.

but the problem is,even if i set the progress-indicator's visibility and availability true before i called the loading function and switching pane function,the progress-indicator only show after the loading was finished.

i tried to set the progress-indicator's visibility and availability in another thread and it also wont work properly(show after the loading)

"loading" in the code is the fxml id of the progressindicator

here is the code:(the code is part of the controller.java)

//open inboxpage
    public void OpenBox() {
        this.loading.setVisible(true);//loading is the id of the progress indicator
        this.loading.setDisable(false);
        
        SendPane.setDisable(true);
        SendPane.setVisible(false);
        SettingPane.setDisable(true);
        SettingPane.setVisible(false);
        
        BoxPane.setDisable(false);
        BoxPane.setVisible(true);
        
        if(account.length()+pwd.length()<2) {
            //this.loading.setVisible(false);
            //this.loading.setDisable(true);
            this.MailDisplay.setText("Please fill in your infos");
        }else {
            this.MailDisplay.clear();
            LoadMails(account,pwd);
            //this.loading.setVisible(false);
            //this.loading.setDisable(true);
        }
    }

the truth is ,if i use the code below,the progress indicator won't show at all(the indicator show after loading,but it was set to unvisible soon after showing)

//open inboxpage
    public void OpenBox() {
        this.loading.setVisible(true);//loading is the id of the progress indicator
        this.loading.setDisable(false);
        
        SendPane.setDisable(true);
        SendPane.setVisible(false);
        SettingPane.setDisable(true);
        SettingPane.setVisible(false);
        
        BoxPane.setDisable(false);
        BoxPane.setVisible(true);
        
        if(account.length()+pwd.length()<2) {
            this.loading.setVisible(false);
            this.loading.setDisable(true);
            this.MailDisplay.setText("Please fill in your infos");
        }else {
            this.MailDisplay.clear();
            LoadMails(account,pwd);
            this.loading.setVisible(false);
            this.loading.setDisable(true);
        }
    }
Boucii
  • 51
  • 6
  • 4
    I guess you need to put the "loading function" in a separate thread, because else it blocks the UI thread, so it does not get updated until the loading has been finished. – anko Jun 29 '20 at 03:32
  • [mcve] please .. and stick to java naming conventions – kleopatra Jun 29 '20 at 07:27
  • 1
    "there is a process where i need to load some information into the pane B and which would take some time" Then that process should be encapsulated as a `Task` and run in a background thread. See https://stackoverflow.com/questions/30249493/using-threads-to-make-database-requests/30250308#30250308 (which refers to database access, but is basically the same issue). – James_D Jun 29 '20 at 12:15
  • than you all . the problem was solved just as what you said. – Boucii Jul 05 '20 at 03:47

1 Answers1

0

Thanks to all who commented above,the problem was solved.

I used another thread to load the information into the pane. before the execute of such thread ,invoke the indicator

setDisable(f);
        setVisible(t);

at end of the run method of this class,invoke indicator.setdisable(t),visible(f)

```
ExecutorService executor = Executors.newCachedThreadPool();
            System.out.println("call thread");
            call(executor,account,pwd);

private synchronized void call (ExecutorService executor,String acc,String pwd) {

    loadBox loader= new loadBox();
    loader.loading=this.loading;
    loader.account = acc;
    loader.pwd= pwd ;
    loader.ChooseMail = ChooseMail ;
    loader.MailDisplay= this.MailDisplay;
    System.out.println("exe thread");
    executor.execute(loader);
}
```
Boucii
  • 51
  • 6