科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道怎样让窗口始终在前

怎样让窗口始终在前

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

  1,The upstair tell you a best way.   2,You can extends JWindow   override show() like this:   public void show()   {   supe

作者:中国IT实验室 来源:中国IT实验室 2007年9月25日

关键字: 编程 java

  • 评论
  • 分享微博
  • 分享邮件

  1,The upstair tell you a best way.
  2,You can extends JWindow
  override show() like this:
  public void show()
  {
  super.show();
  this.requestFocus();
  }
  and then add a window listener for
  the focus lost event:
  
  addFocusListener (new java.awt.event.FocusAdapter () {
  public void focusLost (java.awt.event.FocusEvent evt) {
  this.toFront();
  }
  }
  );
  It seems to work for me...
  
  3.You can also try to use thread, I recommend this way.
  /**
  * Call this from class consructor
  */
  public void initialize() {
  TopThread top = new TopThread();
  top.start();
  }
  
  /**
  * Keep JWindow on top (inner class)
  */
  class TopThread extends Thread {
  public void run() {
  while(true) {
  toFront();
  /**
  * Let 10 milliseconds for other code to execute
  */
  try {
  Thread.sleep(10);
  }
  catch(Exception e) {
  // do what you wanna do
  }
  }
  }
  }
  
  You can see:http://forum.java.sun.com/thread.jsp?forum=57&thread=166992
  That's some others discuss it.
  
  

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件