Kirill Kogan
Kirill Kogan

Reputation: 35

javafx , how to show progress bar while printing into text area

i am new in "programming thing , try to learn . my "app" run bat test files , and all result printed in the textarea , it's working good. but my goal now is to present progress bar that will show the progress while printing into the text area. how can i do it ? I've read some guides and I tried somethings but it doesn't work for me

this is the method behind the button that run the bats files

public void RunTestScrip() throws IOException {

    Process p = Runtime.getRuntime().exec(path);

    final InputStream stream = p.getInputStream();
    new Thread(new Runnable() {
        public void run() {
            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new InputStreamReader(stream));
                String line = null;
                while ((line = reader.readLine()) != null) {                    
                    console.appendText("\n" + line);
                    progressBar.progressProperty().bind(RunTestScrip()); // dont know how to use it right in my code  

                }
            } catch (Exception e) {
                // TODO
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        // ignore
                    }
                }
            }
        }
    }).start();

Upvotes: 0

Views: 1264

Answers (1)

n247s
n247s

Reputation: 1912

I dont think the script is able to update a javafx ProgressBar. The easiest way is to create your own rules about progress (probably based on the output you are currently appending to the console).

Here is a nice tutorial on how to create a working Progressbar in javafx. Hopefully you are able ro figure out a way to update the progress accordingly.

Edit:

I added a small example of what can be found in the tutorial in case the provided link breaks.

// initialization of a progressBar with 'indeterminate progress'
ProgressBar pb = new ProgressBar(-1.0D);

// to set the current state of a progress bar you simply do the following
pb.setProgress(current_progress);

Note that progress is a value between 0.0D and 1.0D (e.g. in percentage). A value of -1.0D indicate that the progress is indeterminate.

Upvotes: 1

Related Questions