Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:20:28+00:00 2026-05-22T17:20:28+00:00

Is there a way for me to get the X and Y values of

  • 0

Is there a way for me to get the X and Y values of a window in java? I read that I’ll have to use runtime, since java can’t mess directly, however I am not so sure of how to do this. Can anyone point me some links/tips on how to get this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:20:29+00:00Added an answer on May 22, 2026 at 5:20 pm

    To get the x and y position of “any other unrelated application” you’re going to have to query the OS and that means likely using either JNI, JNA or some other scripting utility such as AutoIt (if Windows). I recommend either JNA or the scripting utility since both are much easier to use than JNI (in my limited experience), but to use them you’ll need to download some code and integrate it with your Java application.

    EDIT 1
    I’m no JNA expert, but I do fiddle around with it some, and this is what I got to get the window coordinates for some named window:

    import java.util.Arrays;
    import com.sun.jna.*;
    import com.sun.jna.platform.win32.WinDef.HWND;
    import com.sun.jna.win32.*;
    
    public class GetWindowRect {
    
       public interface User32 extends StdCallLibrary {
          User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class,
                   W32APIOptions.DEFAULT_OPTIONS);
    
          HWND FindWindow(String lpClassName, String lpWindowName);
    
          int GetWindowRect(HWND handle, int[] rect);
       }
    
       public static int[] getRect(String windowName) throws WindowNotFoundException,
                GetWindowRectException {
          HWND hwnd = User32.INSTANCE.FindWindow(null, windowName);
          if (hwnd == null) {
             throw new WindowNotFoundException("", windowName);
          }
    
          int[] rect = {0, 0, 0, 0};
          int result = User32.INSTANCE.GetWindowRect(hwnd, rect);
          if (result == 0) {
             throw new GetWindowRectException(windowName);
          }
          return rect;
       }
    
       @SuppressWarnings("serial")
       public static class WindowNotFoundException extends Exception {
          public WindowNotFoundException(String className, String windowName) {
             super(String.format("Window null for className: %s; windowName: %s", 
                      className, windowName));
          }
       }
    
       @SuppressWarnings("serial")
       public static class GetWindowRectException extends Exception {
          public GetWindowRectException(String windowName) {
             super("Window Rect not found for " + windowName);
          }
       }
    
       public static void main(String[] args) {
          String windowName = "Document - WordPad";
          int[] rect;
          try {
             rect = GetWindowRect.getRect(windowName);
             System.out.printf("The corner locations for the window \"%s\" are %s", 
                      windowName, Arrays.toString(rect));
          } catch (GetWindowRect.WindowNotFoundException e) {
             e.printStackTrace();
          } catch (GetWindowRect.GetWindowRectException e) {
             e.printStackTrace();
          }      
       }
    }
    

    Of course for this to work, the JNA libraries would need to be downloaded and placed on the Java classpath or in your IDE’s build path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get the values of various properties of (both .NET
Is there any way to get available values for SET field in table? Thank
Is there a way to get all possible values from a MySQL enum column?
Is there a better way than using globals to get interesting values from a
Is there a way to get the value of a HashMap randomly in Java?
Possible Duplicate: How can I get query string values? Lets say, we have a
Is there a way to get the value of the WTSSessionID parameter in a
Is there a way to get all the querystring name/value pairs into a collection?
is there a way to get sine and cosine of a value in sqlite
Is there a way to get the C++ pre-processor to expand a #define'ed value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.