Blink jframe in swing without transferring focus

一世执手 提交于 2020-01-01 19:32:30

问题


I want to blink my jframe's entry in taskbar but do not want it to get focused. I read about in on net and tried different solutions but none of them worked for me.

In my case I have a main jframe which has 2 buttons on click of which 2 jframes are opened. Both jframe listens to some event messages and on receiving of message it should blink if not focused.

I have tried following:

  1. frame.toFront();
  2. frame.requestFocus();
  3. frame.firePropertyChange();
  4. frame.setVisible(true);

They all worked well in blinking windows but the focus also gets transfered to that window which I don't want it do. How can I stop focus transfer? I have also tried calling transferFocus(); after the above options but didn't worked.

I have searched on SO but didn't find the solution. The questions I found are

  • How can I flash the Windows taskbar using Swing?
  • JFrame to be displayed when the event occurs?

My current code:-

public void OnEvent(){
    Toolkit.getDefaultToolkit().beep();  
    if(!hasFocus()){
         toFront(); //requestFocus(); //setVisible(true); //firePropertyChange("",false,true);
    }
}

来源:https://stackoverflow.com/questions/6423987/blink-jframe-in-swing-without-transferring-focus

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!