使用Java,您可以使用TrayIcon和java.awt.SystemTray创建一个trayicon。但是,当您将Windows与4K监视器结合使用时,此图标看起来很糟糕,Windows会自动扩展所有更大的内容。
Java将trayiconsize设置为16x16,但这对于缩放模式来说太小了,因此它看起来很糟糕。你知道怎么解决这个问题吗?
修改
以下是结果的示例代码和屏幕截图。我正在使用宝马的徽标(256x256像素):)
package trayicon;
import java.awt.AWTException;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Trayicon {
public static void main(String[] args) throws IOException {
//Check the SystemTray is supported
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
BufferedImage img = ImageIO.read(new File("256x256.png"));
final TrayIcon trayIcon =
new TrayIcon(img, "Trayicon");
trayIcon.setImageAutoSize(true);
final SystemTray tray = SystemTray.getSystemTray();
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
}
System.in.read();
System.exit(0);
}
}
结果(查看右下角的图标):