0
更改當前系統的屏幕分辨率正常,但我需要更改遠程會話的屏幕分辨率(可能位於virtualbox中)。這是連接和通過程序我需要改變它。形成基於web的應用程序,我將通過提供參數來調用runnable jar文件。使用Java RunnableJar更改遠程會話的屏幕分辨率
public static void main(String[] args) throws InterruptedException, IOException {
screenResolution(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])); // Screen Resolution of Remote Session.
}
public static void screenResolution(int width, int height, int bitDepth, int refreshRate) throws InterruptedException{
java.awt.GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
java.awt.DisplayMode change_Mode = new DisplayMode(width, height, bitDepth, refreshRate);//DisplayMode.REFRESH_RATE_UNKNOWN);
DisplayMode[] supportedResolutions = graphicsDevice.getDisplayModes();
System.out.println(supportedResolutions.length);
for (DisplayMode resolution : supportedResolutions) {
System.out.format("%d by %d, (%dbit), %d Hertz \n", resolution.getWidth(), resolution.getHeight(), resolution.getBitDepth(), resolution.getRefreshRate());
if (resolution.equals(change_Mode)) {
System.out.format("supported = %s\n",resolution);
DisplayMode current_displayMode = graphicsDevice.getDisplayMode();
if (change_Mode.equals(current_displayMode))
System.out.println("=== No need to change Resolution ===");
else {
java.awt.GraphicsConfiguration graphConfig = graphicsDevice.getDefaultConfiguration();
javax.swing.JFrame frame = new JFrame("",graphConfig);
setResolution(graphicsDevice, frame, change_Mode);
}
break;
}
}
}
public static void setResolution(GraphicsDevice graphicsDevice, JFrame frame, DisplayMode displayMode) throws InterruptedException{
try {
graphicsDevice.setFullScreenWindow(frame);
graphicsDevice.setDisplayMode(displayMode);
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
System.out.println("After Cahange Resolution : "+screenSize.getWidth()+" * "+screenSize.getHeight());
// doing other work......
Thread.sleep(1*60*1000); // min sec millisec
}catch(IllegalArgumentException e){
e.printStackTrace();
}finally{
frame.dispose(); //program terminates. screen resolution changes to previous resolution.
}
}
運行我的jar文件在當前機器從控制檯D:\JarLocation>java -jar ChangeResolution.jar 1366 768 32 60
它工作正常。但我需要改變屏幕的分辨率,當客戶端有什麼不同的分辨率來測試他的senario。
我在遠程計算機上運行同一個jar文件,但它不能更改。
即使mannually我也不能改變它。它說的顯示設置不能改變。