I got a problem with setting a value to a JProgressBar which i got from inside a type returning method. I know I have to do multi threading but I´m really new to this topic and really don´t know how to implement this.
I try to briefly explain my dilemma in code:
This is my data returning method to count lines in a String (e.g. from a JTextArea or whatsoever).
    public static int countLines(String s) {
        int count = 0;
        String[] words = s.split("\n");
        for(String i: words) {
            count++;
        }
        return count;
    }
What I want to add is a method inside this method that sets my JProgressBar that I created in my JFrame to the value count. E.g. setProgress(count);
Is this even possible? Because i tried several ways of doing this and no matter what, the progressbar only updates AFTER the return value has been sent out.
Do I have to run this method in an own Thread or just the progress setting method? or both?
Cheers!