[英]JFrame popup without taskbar icon
我創建了從JFrame繼承的通知窗口,但它們在Windows任務欄中以新圖標顯示。 是否可以在出現通知時(例如,在Skype中,當出現新消息時)突出顯示主應用程序圖標,而在通知窗口的任務欄中不顯示新圖標?
這是彈出代碼:
public class NotificationWindow extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
static private int m_count = 0;
public NotificationWindow(String text)
{
super("NotificationWindow");
setLayout(new GridBagLayout());
setSize(300, 70);
setLocationRelativeTo(null);
setOpacity(0.77f);
setUndecorated(true);
setResizable(false);
add(new JLabel(text));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt)
{
--m_count;
}
});
++m_count;
}
static public int GetWindowCount()
{
return m_count;
}
static public void ShowNotificationWindow(final String text)
{
// Determine if the GraphicsDevice supports translucency.
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment
.getLocalGraphicsEnvironment();
final GraphicsDevice graphicsDevice = graphicsEnvironment
.getDefaultScreenDevice();
// If translucent windows aren't supported, exit.
if (!graphicsDevice.isWindowTranslucencySupported(TRANSLUCENT))
{
System.err.println("Translucency is not supported");
System.exit(0);
}
JFrame.setDefaultLookAndFeelDecorated(true);
// Create the GUI on the event-dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run()
{
NotificationWindow notificationWindow = new NotificationWindow(
text);
Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(
notificationWindow.getGraphicsConfiguration());
int taskBarSize = scnMax.bottom;
Rectangle rect = graphicsDevice.getDefaultConfiguration()
.getBounds();
int x = (int) rect.getMaxX() - notificationWindow.getWidth();
int y = (int) rect.getMaxY() - notificationWindow.getHeight()
- taskBarSize - ((m_count - 1) % 7)
* notificationWindow.getHeight();
notificationWindow.setLocation(x, y);
notificationWindow.setVisible(true);
}
});
}
}
不要擴展JFrame,而是擴展JDialog
通常,任何應用程序都應該只有一個JFrame。 其他子窗口應該是JDialogs。 請參閱: 使用多個JFrame:良好還是不良做法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.