"总在最前"窗户与Java [英] "Always on Top" Windows with Java
问题描述
在Java中,有没有办法有一个窗口,是总在最前面不管用户将焦点切换到另一个应用程序?我在网上搜索,所有的解决方案,瘦某种与本地绑定JNI接口。这真是不能做到这一点的唯一途径?..或者是什么呢?
In Java, is there a way to have a window that is "Always on top" regardless if the user switches focus to another application? I've searched the web, and all of the solutions lean to some sort of JNI interface with native bindings. Truly this can't be the only way to do it?.. or is it?
推荐答案
尝试窗口
类的这个方法:
<一个href=\"http://java.sun.com/javase/6/docs/api/java/awt/Window.html#setAlwaysOnTop%28boolean%29\">Window.setAlwaysOnTop(boolean)
它的工作方式相同,在Windows任务管理器的默认:切换到另一个应用程序,但它始终显示在顶部
It works the same way as the default in the Windows TaskManager: switch to another app but it shows always on top.
这是在Java 1.5中加入
This was added in Java 1.5
样code:
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Annoying {
public static void main(String[] args) {
JFrame frame = new JFrame("Hello!!");
// Set's the window to be "always on top"
frame.setAlwaysOnTop( true );
frame.setLocationByPlatform( true );
frame.add( new JLabel(" Isn't this annoying?") );
frame.pack();
frame.setVisible( true );
}
}
<子>不活跃,即使窗口保持在最前面
这篇关于&QUOT;总在最前&QUOT;窗户与Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!