Skip to content

Dansoftowner/FXTaskbarProgressBar

Repository files navigation

JavaFXTaskbarProgressbar

A clean and easy way to implement this amazing native Windows taskbar-progressbar functionality in javaFX

This library allows you to add native taskbar-progressbar functionality to your JavaFX Stages.

For the native access this project uses bridj

Compatibility

This library has support for java 8 and java 11 too.
Note: if you use java 11 you have to pass this VM argument: --add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED

Source code

This project has two important branches:

  • "master" - for java 8 builds
  • "11" - for java 11 builds

Background

Since Windows 7 there is a taskbar-progressbar feature in Windows systems that basically means that you can see a progress on the program's icon. A good example for this when you copy something using the file explorer:
Taskbar progressbar in windows 7
This is very useful because you don't have to open the window to see the progress! The problem is that javaFX doesn't provide this functionality by default... however you can easily implement it with this library!
It enables you to do this in pure java!

How to include it to your project

You can download the right jar file from the releases.
Every release has two jar files: one is a fat jar (it's name ends with '*-full-x.x.jar') that contains the bridj binaries as well (so if you use this you don't have to include bridj separately for your project); and another jar that doesn't contain the external bridj binaries (in this case you have to download the bridj binaries separately).
The 'v11.x' versions are for java11 users and the 'v8.x' versions are for java 8 users.

How to use it Tutorial

0. Types of progressbar

Before we jump in, we have to know the 4 types of a taskbar-progressbar:

  • NORMAL - a progressbar with normal green color
  • PAUSED - a progressbar with a yellow color
  • ERROR - a progressbar with a red color
  • INDETERMINATE - a progressbar that doesn't show any fix progress
  • NO_PROGRESS - a progressbar that doesn't show anything

    All these types are represented by an enum called com.nativejavafx.taskbar.TaskbarProgressbar.Type.

Now let's see how can we actually use this through code.
There are multiple ways to create taskbar progressbars with this library:

1.Through static methods:

Firstly you have to import the necessary class:

import com.nativejavafx.taskbar.TaskbarProgressbar; 

...and you have to show the javafx Stage before any operation:

primaryStage.show();

Then call the static method:

TaskbarProgressbar.showCustomProgress(primaryStage, 50, 100, TaskbarProgressbar.Type.NORMAL);

Well, the code above looks okay, but it's not safe. This functionality isn't supported by every OS. For example on a Linux Ubuntu system it will definitely throw a RuntimeException because it's only available on Windows 7+ systems.
If you use static methods to create taskbar-progressbars you always have to check that the current OS supports this functionality!

So let's correct the code:

if (TaskbarProgressbar.isSupported()) {
    TaskbarProgressbar.showCustomProgress(primaryStage, 50, 100, TaskbarProgressbar.Type.NORMAL);
}

...now it is safe!

Result:
Normal Taskbar progressbar

You have to do a similar thing if you want to show an indeterminate progress:

if (TaskbarProgressbar.isSupported()) {
    TaskbarProgressbar.showIndeterminateProgress(primaryStage);
}

Result:
Indeterminate Taskbar progressbar

To stop the progress:

TaskbarProgressbar.stopProgress(primaryStage);

2. Through instantiation (the recommended way)

Firstly (after you imported the necessary class) create a TaskbarProgressbar instance with the help of TaskbarProgressbarFactory:

TaskbarProgressbar progressbar = TaskbarProgressbarFactory.getTaskbarProgressbar(primaryStage);

Before any operation you have to show the Stage:

primaryStage.show();

After that just use the created instance for the operations:

progressbar.showCustomProgress(50, 100, TaskbarProgressbar.Type.NORMAL);

Note: in this case to check that the OS supports this functionality is unnecessary because the object checks it automatically!

The result is the same:
Normal Taskbar progressbar

If you want an indeterminate process:

progressbar.showIndeterminateProgress();

To stop the progress:

progressbar.stopProgress();

Bonus features

A simple method for showing a fully loaded error progressbar

progressbar.showFullErrorProgress();
//equivalent to progressbar.showCustomProgress(100, 100, TaskbarProgressbar.Type.ERROR) 

Result:
Full errror taskbar progress

Also:

progressbar.showFullNormalProgress();
progressbar.showFullPausedProgress();

More screenshots

Some more screenshots about what can you do with this library

  • A paused progress example:
    Code: progressbar.showCustomProgress(70, 100, TaskbarProgressbar.Type.PAUSED);
    Paused progress
  • An error progress example:
    Code: progressbar.showCustomProgress(40, 100, TaskbarProgressbar.Type.ERROR);
    Paused progress

Full demo

A full demo-example class is available here.

Support

If you like this library please give me a star! It's very important for me because it keeps me motivated to work on this library. Thank you!

About

A library for JavaFX that gives you the ability to show progress on the Windows taskbar.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages