电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

怎样让窗口始终在前


发布日期:2023/3/6
 

The upstair tell you a best way

You can extends JWindow

override show() like this:

public void show()

{

supershow();

thisrequestFocus();

}

and then add a window listener for

the focus lost event:

addFocusListener (new javaawteventFocusAdapter () {

public void focusLost (javaawteventFocusEvent evt) {

thistoFront();

}

}

);

It seems to work for me

You can also try to use thread I recommend this way

/**

* Call this from class consructor

*/

public void initialize() {

TopThread top = new TopThread();

topstart();

}

/**

* Keep JWindow on top (inner class)

*/

class TopThread extends Thread {

public void run() {

while(true) {

toFront();

/**

* Let milliseconds for other code to execute

*/

try {

Threadsleep();

}

catch(Exception e) {

// do what you wanna do

}

}

}

}

You can see:?forum=&thread=

Thats some others discuss it

上一篇:死锁

下一篇:一组常用的弹出窗口用法总结