Windows最小化拖盘其实就是将程序放到托盘里面,需要的时候再点击托盘里面的应用图标,此时就可以正常使用应用了,托盘如下:
下面是一个简单的Java程序,可以把窗口最小化到系统托盘:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TrayIconDemo {
private static void createAndShowGUI() {
// 检查系统是否支持托盘
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon =
new TrayIcon(createImage("icon.png", "tray icon"));
final SystemTray tray = SystemTray.getSystemTray();
// 添加一个打开菜单项