简体   繁体   中英

Position and size of window whith Desktop Java class

The following code opens a text file with the application that the operating system has set.

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class Main {
  public static void main(String[] a) {
    try {
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
      }

       desktop.open(new File("c:\\a.txt"));
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }

  }
}

From here, I can know the size and position of the window that opens?

Thanks for the help.

Greetings.

I do not believe there is a simple way. The method doesn't return anything and window that opens will be a completely separate application anyway.

There might be a way that would be OS specific to look at running processes and build something to collect this information but it would not be easy.

If you wnat to use the Java Toolkit class, so the following Java code demonstrates how to get the screen size:

// screen size with Dimension Class
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

After you get the screen size as a Dimension object, you can get the height and width as follows:

// screen height
screenSize.getHeight();

// screen width
screenSize.getWidth();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM