问题描述
(解决:一个的WindowStateListener
和递延调用 toBack后
只要窗口集中)
大家好!
我一直在试图找出如何使 java.awt.Window中的
(任何子类都行),因此它不能被带到前面。我工作在出现下面的所有应用程序窗口,并在屏幕上显示一个小工具Java的Samurize样程序。就像始终,我希望的简单的东西,希望只是一个单一的方法调用,如果可能的话,但我已经通过API文档检查,我有没有运气。
编辑:
对不起,我的意思是永远在底部,而不是简单的unfocusable。
下面是一个基本的测试用例。当在窗口点击,它不应该高于其他任何当前在屏幕上:
进口java.awt中的*。
进口的javax.swing *。公共类主要扩展的JFrame {
公众的Main(){
。DIM维= Toolkit.getDefaultToolkit()getScreenSize(); setFocusable(假);
setFocusableWindowState(假);
的setBounds(新的Rectangle(DIM)); toBack后();
} 公共静态无效的主要(字串[] args){
新的main()的调用setVisible(真);
}
}
您想要使用<$c$c>setFocusableWindowState(false)$c$c>
(FWIW,这是由后上方答案链接的API文档你提到的)
编辑:增加一个监听器窗口状态更改,执行什么<$c$c>toBack()$c$c>?
编辑:你也可以考虑从拉动窗口前重写 toFront
方法prevent什么
(SOLVED: a WindowStateListener
and a deferred call to toBack
whenever the window is focused)
Hello all!
I've been trying to figure out how to make a java.awt.Window
(any subclass will do) so that it cannot be brought to the front. I'm working on a Java "Samurize-like" program that appears below all the application windows and displays Widgets on the screen. Just like "Always on top windows with Java", I'm hoping for something simple, hopefully just a single method call, if possible, but I've checked through the API docs and I've had no luck.
Edit:Sorry, I meant "always on bottom" rather than simply "unfocusable".
Here's a basic test case. When clicking on the Window, it should not come above any others currently on the screen:
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame {
public Main() {
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setFocusable(false);
setFocusableWindowState(false);
setBounds(new Rectangle(dim));
toBack();
}
public static void main(String[] args) {
new Main().setVisible(true);
}
}
You want to use setFocusableWindowState(false)
(fwiw, this was in the API document linked by the top answer of the post you referred to)
edit: what about adding a listener to window state change that executes toBack()
?
edit: you might also consider overriding the toFront
method to prevent anything from pulling the window to the front.
这篇关于制作Java中的Unfocusable窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!