服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > 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.

扫描关注微信公众号