问题描述
我想知道当文件操作正在进行时,是否可以像 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: // http://www.51sjk.com/Upload/Articles/1/0/335/335943_20221103094247430.html // MSDNDoc: // http://www.51sjk.com/Upload/Articles/1/0/335/335943_20221103094248391.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); } }