7

(解決済み:ウィンドウがフォーカスされているときはいつでもWindowStateListener呼び出しを延期)toBack

皆さんこんにちは!

私はjava.awt.Window(どのサブクラスでも可能です) を作成して前面に出すことができないようにする方法を見つけようとしています。私は、すべてのアプリケーション ウィンドウの下に表示され、画面にウィジェットを表示する Java の「Samurize のような」プログラムに取り組んでいます。「常に Java でウィンドウを最前面に表示する」のように、できれば単一のメソッド呼び出しだけで済むような単純なものを望んでいますが、API ドキュメントを確認しましたが、うまくいきませんでした。

編集:申し訳ありませんが、単に「フォーカスできない」というよりも「常に下にある」という意味でした。

これが基本的なテストケースです。ウィンドウをクリックすると、現在画面上にある他のウィンドウの上に来てはいけません。

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);
    }
}
4

2 に答える 2

9

使いたいsetFocusableWindowState(false)

(fwiw、これはあなたが参照した投稿の一番上の回答によってリンクされたAPIドキュメントにありました)

編集:実行するウィンドウ状態の変更にリスナーを追加するのはtoBack()どうですか?

編集:toFrontメソッドをオーバーライドして、ウィンドウが前面に引っ張られないようにすることも検討してください。

于 2010-01-09T03:38:44.440 に答える
1

setFocusableWindowState

public void setFocusableWindowState(boolean focusableWindowState)

Sets whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow. If this Window's focusable Window state is set to false, then isFocusableWindow will return false. If this Window's focusable Window state is set to true, then isFocusableWindow may return true or false depending upon the other requirements which must be met in order for a Window to be focusable.

Setting a Window's focusability state to false is the standard mechanism for an application to identify to the AWT a Window which will be used as a floating palette or toolbar, and thus should be a non-focusable Window. Setting the focusability state on a visible Window can have a delayed effect on some platforms — the actual change may happen only when the Window becomes hidden and then visible again. To ensure consistent behavior across platforms, set the Window's focusable state when the WIndow is invisible and then show it.

Parameters:
    focusableWindowState - whether this Window can be the focused Window
Since:
    1.4
See Also:
    isFocusableWindow(), getFocusableWindowState(), isShowing(), Component.setFocusable(boolean)

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Window.html#setFocusableWindowState%28boolean%29

于 2010-01-09T03:40:08.033 に答える