开发者

Position and size of window whith Desktop Java class

开发者 https://www.devze.com 2023-01-28 04:39 出处:网络
The following code opens a text file with the application that the operating system has set. import java.awt.Desktop;

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;
开发者_StackOverflow中文版
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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号