制作Java中的Unfocusable窗口 [英] Making an Unfocusable Window in Java

查看:167
本文介绍了制作Java中的Unfocusable窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(解决:一个的WindowStateListener 和递延调用 toBack后只要窗口集中)

大家好!

我一直在试图找出如何使 java.awt.Window中的(任何子类都行),因此它不能被带到前面。我工作在出现下面的所有应用程序窗口,并在屏幕上显示一个小工具Java的Samurize样程序。就像始终在上面的窗口与Java ,我希望的简单的东西,希望只是一个单一的方法调用,如果可能的话,但我已经通过API文档检查,我有没有运气。

编辑:
对不起,我的意思是永远在底部,而不是简单的unfocusable。

下面是一个基本的测试用例。当在窗口点击,它不应该高于其他任何当前在屏幕上:

 进口java.awt中的*。
进口的javax.swing *。公共类主要扩展的JFrame {
    公众的Main(){
        。DIM维= Toolkit.getDefaultToolkit()getScreenSize();        setFocusable(假);
        setFocusableWindowState(假);
        的setBounds(新的Rectangle(DIM));        toBack后();
    }    公共静态无效的主要(字串[] args){
        新的main()的调用setVisible(真);
    }
}


解决方案

您想要使用<一个href=\"http://java.sun.com/javase/6/docs/api/java/awt/Window.html#setFocusableWindowState%28boolean%29\"><$c$c>setFocusableWindowState(false)

(FWIW,这是由后上方答案链接的API文档你提到的)

编辑:增加一个监听器窗口状态更改,执行什么<一个href=\"http://java.sun.com/javase/6/docs/api/java/awt/Window.html#toBack%28%29\"><$c$c>toBack()?

编辑:你也可以考虑从拉动窗口前重写 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窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆