怎样让窗口始终在前

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航