如何在Mac Dock中使我的应用程序图标d跳

如何在Mac Dock中使我的应用程序图标d跳,第1张

如何在Mac Dock中使我的应用程序图标d跳

在MacOS下,尝试使用类似Application#requestUserAttention(boolean)

import com.apple.eawt.Application;...Application application = Application.getApplication();application.requestUserAttention(false);

nb-我还没有尝试过-抱歉。

更新了示例

从JavaDocs

要求用户注意此应用程序(通常通过d跳Dock图标)。关键请求将继续跳出Dock图标,直到激活该应用程序为止。已经活动的请求关注的应用程序什么也不做。

这意味着,如果应用程序具有焦点,则该方法将不执行任何 *** 作。

在Mac OSX 10.7.5,Java 1.7.0_07上测试

import com.apple.eawt.Application;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.EventQueue;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.IOException;import javax.imageio.ImageIO;import javax.swing.Jframe;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.Timer;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;public class TestMacIcon {    public static void main(String[] args) {        new TestMacIcon();    }    public TestMacIcon() {        EventQueue.invokeLater(new Runnable() { @Override public void run() {     try {         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());     } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {     }     Jframe frame = new Jframe("Test");     frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);     frame.setLayout(new BorderLayout());     frame.add(new TestPane());     frame.pack();     frame.setLocationRelativeTo(null);     frame.setVisible(true); }        });    }    public class TestPane extends JPanel {        public TestPane() { final Application application = Application.getApplication(); addMouseListener(new MouseAdapter() {     @Override     public void mouseClicked(MouseEvent e) {         try {  System.out.println("clicked");  application.requestUserAttention(true);  application.setDockIconImage(ImageIO.read(getClass().getResource("/Java.png")));  application.setDockIconBadge("Blah");  application.requestUserAttention(true);         } catch (IOException ex) {  ex.printStackTrace();         }     } }); Timer time = new Timer(2000, new ActionListener() {     @Override     public void actionPerformed(ActionEvent e) {         if (!SwingUtilities.getWindowAncestor(TestPane.this).hasFocus()) {  ((Timer)e.getSource()).stop();  System.out.println("Pay attention!!");  application.requestUserAttention(true);         }     } }); time.setRepeats(true); time.setCoalesce(true); time.start();        }        @Override        public Dimension getPreferredSize() { return new Dimension(200, 200);        }    }}

PS确保您专注于应用程序;)



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5500430.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-13
下一篇2022-12-13

发表评论

登录后才能评论

评论列表(0条)

    保存