Reputation: 99
I'm working on a desktop app, my goal is to fetch a given URL with Jsoup.connect()
.
Works fine, but it takes a couple of secs, so I tought I'll display a "loading" gif or something while it's not complete.
Fetch and display the loading JPanel for same button click.
If I just want to set my JPanel visible for button click, works fine (code below)
private void btnRefreshSelectedActionPerformed(ActionEvent e)
{
panelRefresh.setVisible(true);
}
But when I add the url fetching, my Panel won't show up, but should see it for 1-3 secs. Code:
private void btnRefreshSelectedActionPerformed(ActionEvent e)
{
panelRefresh.setVisible(true);
//SwingUtilities.invokeLater(() -> panelRefresh.setVisible(true)); - still not working
//do Jsoup.connect and other things (1-3 secs runtime)
//...
panelRefresh.setVisible(false);
}
What is the problem?
Upvotes: 0
Views: 444
Reputation: 2740
I'm not familiar with Jsoup API, so just guessing, but.. are you sure the method Jsoup.connect()
is synchronous? Perhaps it just initiates connection on a separate thread and returns immediately, then the other thread calls some handler when connection got established?
In that case your JPanel visibility is immediately switched to false after true, so in practice you don't see it at all. If that's the case then you should change the visibility on the handler called when connection gets established rather than in btnRefreshSelectedActionPerformed
method.
Upvotes: 1