3

さまざまなコンポーネントを含めることができるメイン アプリケーションの JFrame ウィンドウがあります。ユーザーが編集可能なテキストフィールドを選択すると、自己実装の OnScreenKeyboard が開きます。OSK も JFrame ウィンドウです。

ユーザーがメイン ウィンドウを別のモニターにドラッグすると、OSK も同じモニターに表示されます。このために、メインの JFrame が表示されているモニターを検出する必要があります。

私は方法を見つけようとします

Toolkit.getDefaultToolkit()

しかし、何かを見つけることができませんでした。

JFrameが表示されているモニターを検出する方法を知っていますか?

Java バージョン 1.4 Windows XP

ありがとう

4

1 に答える 1

5

利用可能なすべてのモニターのソリューションが同じである場合、答えてください。

AWTの場合:

すべてのコントロールには getMonitor() メソッドがあり、そこから画面位置の取得を次のように計算できます。

Monitor widgetMonitor = mTextWidget.getMonitor();
Rectangle monitorRect = widgetMonitor.getBounds();

if(monitorRect.x < 0){
   // shown in left monitor, starting from the main monitor
}

if(monitorRect.x > monitorRect.width){
   // shown in right monitor, starting from the main monitor
}

SWTの場合:

それは私の元のコードのほんの一部です。戻り値が null でないかどうか、次のように尋ねる必要があります。

    int monitorWidth = 0;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screenDevices = ge.getScreenDevices();
    if(screenDevices.length > 0){
        monitorWidth = screenDevices[0].getDisplayMode().getWidth();
    }


    Point ownerLocationOnScreen = owner.getLocationOnScreen();

    int screenMovingX = 0;
    if(ownerLocationOnScreen.x < 0){
        screenMovingX = -monitorWidth;
    }
    if(ownerLocationOnScreen.x > monitorWidth){
        screenMovingX = monitorWidth;
    }
于 2009-01-16T14:15:09.637 に答える