我认为没有平台独立的方法可以做到这一点。您将必须查看特定于平台的API调用,并通过JNI或JNA实现它们。
对于Windows,这是我自己的一个应用程序的摘录:
public static void flashWindow(final Shell shell, boolean flashTray, boolean flashWindow) { try { if (isActiveWindow(shell)) { flashWindow = false; flashTray = false; } User32 lib = (User32) getLibrary("user32", User32.class); User32.FLASHWINFO flash = new User32.FLASHWINFO(); flash.hWnd = new W32API.HANDLE(new W32API.UINT_PTR(shell.handle) .toPointer()); flash.uCount = 2; flash.dwTimeout = 1000; if (flashTray || flashWindow) { flash.dwFlags = (flashTray ? User32.FLASHW_TRAY : 0) | (flashWindow ? User32.FLASHW_CAPTION : 0); } else { flash.dwFlags = User32.FLASHW_STOP; } flash.cbSize = flash.size(); if (lib.FlashWindowEx(flash) && !flashWindow) { final FocusListener focusListener = new FocusListener() { public void focusGained(FocusEvent arg0) { flashWindow(shell, false, false); shell.removeFocusListener(this); } public void focusLost(FocusEvent arg0) { } }; shell.addFocusListener(focusListener); } } catch (UnsatisfiedlinkError e) { }}
这是的简化版本
getLibrary():
protected static StdCallLibrary getLibrary(String libraryName, Class<?> interfaceClass) throws UnsatisfiedlinkError { try { StdCallLibrary lib = (StdCallLibrary) Native.loadLibrary(libraryName, interfaceClass); return lib; } catch (UnsatisfiedlinkError e) { Logger.out.error("Could not load " + libraryName + " library."); throw e; }}
使用
dispose()完库后,请多加注意。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)