質問

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

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

メソッドを見つけようとしています

Toolkit.getDefaultToolkit()

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

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

Javaバージョン1.4 Windows XP

ありがとう

役に立ちましたか?

解決

使用可能なすべてのモニターのソリューションが同じ場合は、回答します。

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;
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top