Following method call prevents JLabel from getting visible

32 views Asked by At

I have a short question. I tried to google it, but it seems, that I can't find the correct keywords for good results. So here is my problem:

I have a JButton. Its actionPerformed is doing this:

public void actionPerformed(ActionEvent e) {
                lblConverting.setVisible(true);
                input.writeToCSV(chosenPath);
                lblConverting.setVisible(false);
                lblSuccess.setVisible(true);    
            }

Due to the long execution of my writeToCSV-method, I want to show a message, which my lblConverting contains. So during the execution of writeToCSVthe user should see a message, which tells him to wait some minutes. Instead it looks like, that lblConvertinggets visible "too late", so that it is set invisible shortly after writeToCSVis finished, right before it gets invisible again.

So, is there a way to get that label visible, before the method executes? Should I use something like SwingWorker? The first line of the actionPerformed is the only place in my code, where I want to do this. So a really short solution is preferred.

0

There are 0 answers