龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

怎样让窗口始终在前

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
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.

  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.
  
精彩图集

赞助商链接