Java 中的 Windows 7 任务栏进度条
我想知道当文件操作正在进行时,是否可以像 Windows 资源管理器那样在任务栏上显示进度条?
I'd like to know if it is possible to make a progress bar displayed on the taskbar like Windows Explorer does when there's a file operation going on?
我看过很多例子,但都涉及到 C#.
I saw many examples, but they all involved C#.
SWT 不会削减它.
推荐答案
我发现Java 9中包含了这个功能.它是 AWT 的一部分,使用起来也非常简单.
I found out that this feature is included in Java 9. It is part of AWT and it is quity simple too use.
这是一个简短的例子:
import java.awt.Taskbar;
import java.awt.Taskbar.State;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
/**
* @author fxl
*/
public class TaskbarSample {
public static void main(String[] args) {
// JavaDoc:
// https://docs.oracle.com/javase/9/docs/api/java/awt/Taskbar.html
// MSDNDoc:
// https://msdn.microsoft.com/en-us/library/dd391692(VS.85).aspx
if (Taskbar.isTaskbarSupported() == false) {
return;
}
JFrame dialog = new JFrame("Test - 50%");
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
Taskbar taskbar = Taskbar.getTaskbar();
taskbar.setWindowProgressState(dialog, State.ERROR);
taskbar.setWindowProgressValue(dialog, 50);
}
}
相关文章