import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit; public Rectangle getDestktopRectangle(){
Rectangle windowSize = new Rectangle();
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()); //获取屏幕可以利用的width和height
//windowSize.setBounds(scrInsets.left, scrInsets.top, scrSize.width - scrInsets.left - scrInsets.right, scrSize.height - scrInsets.top - scrInsets.bottom); //获取屏幕的分辨率
windowSize.setBounds(scrInsets.left, scrInsets.top, scrSize.width, scrSize.height);
logger.info("The desktop resolution is : " + windowSize);
return windowSize;
} public void setDestktopRectangle(int width, int height){
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device=environment.getDefaultScreenDevice(); //取得所支持的分辨率
DisplayMode[] displayModes= device.getDisplayModes();
for(DisplayMode displayMode : displayModes){
logger.info("Available display mode : ["+displayMode.getWidth()+" , "+displayMode.getHeight()+" , "+displayMode.getBitDepth()+" , "+displayMode.getRefreshRate()+"]");
} //new DisplayMode(分辨率宽,分辨率高,颜色位数,刷新率)
DisplayMode displayMode=new DisplayMode(width,height,16,75);
device.setDisplayMode(displayMode);
}

设置屏幕分辨率不一定好使。

输出结果:

[{1115337740}]***The desktop resolution is : java.awt.Rectangle[x=0,y=0,width=1280,height=1024]

[{1115337740}]***Available display mode : [640 , 480 , 32 , 60]

[{1115337740}]***Available display mode : [640 , 480 , 32 , 59]

[{1115337740}]***Available display mode : [640 , 480 , 32 , 75]

[{1115337740}]***Available display mode : [720 , 480 , 32 , 60]

[{1115337740}]***Available display mode : [720 , 480 , 32 , 75]

[{1115337740}]***Available display mode : [720 , 576 , 32 , 60]

[{1115337740}]***Available display mode : [720 , 576 , 32 , 75]

[{1115337740}]***Available display mode : [800 , 600 , 32 , 60]

[{1115337740}]***Available display mode : [800 , 600 , 32 , 75]

[{1115337740}]***Available display mode : [1024 , 768 , 32 , 60]

[{1115337740}]***Available display mode : [1024 , 768 , 32 , 75]

[{1115337740}]***Available display mode : [1152 , 864 , 32 , 60]

[{1115337740}]***Available display mode : [1152 , 864 , 32 , 75]

[{1115337740}]***Available display mode : [1280 , 720 , 32 , 60]

[{1115337740}]***Available display mode : [1280 , 720 , 32 , 59]

[{1115337740}]***Available display mode : [1280 , 720 , 32 , 75]

[{1115337740}]***Available display mode : [1280 , 768 , 32 , 60]

[{1115337740}]***Available display mode : [1280 , 768 , 32 , 75]

[{1115337740}]***Available display mode : [1280 , 960 , 32 , 60]

[{1115337740}]***Available display mode : [1280 , 960 , 32 , 75]

[{1115337740}]***Available display mode : [1280 , 1024 , 32 , 60]

[{1115337740}]***Available display mode : [1280 , 1024 , 32 , 75]

[{1115337740}]***Available display mode : [640 , 480 , 16 , 60]

[{1115337740}]***Available display mode : [640 , 480 , 16 , 59]

[{1115337740}]***Available display mode : [640 , 480 , 16 , 75]

[{1115337740}]***Available display mode : [720 , 480 , 16 , 60]

[{1115337740}]***Available display mode : [720 , 480 , 16 , 75]

[{1115337740}]***Available display mode : [720 , 576 , 16 , 60]

[{1115337740}]***Available display mode : [720 , 576 , 16 , 75]

[{1115337740}]***Available display mode : [800 , 600 , 16 , 60]

[{1115337740}]***Available display mode : [800 , 600 , 16 , 75]

[{1115337740}]***Available display mode : [1024 , 768 , 16 , 60]

[{1115337740}]***Available display mode : [1024 , 768 , 16 , 75]

[{1115337740}]***Available display mode : [1152 , 864 , 16 , 60]

[{1115337740}]***Available display mode : [1152 , 864 , 16 , 75]

[{1115337740}]***Available display mode : [1280 , 720 , 16 , 60]

[{1115337740}]***Available display mode : [1280 , 720 , 16 , 59]

[{1115337740}]***Available display mode : [1280 , 720 , 16 , 75]

[{1115337740}]***Available display mode : [1280 , 768 , 16 , 60]

[{1115337740}]***Available display mode : [1280 , 768 , 16 , 75]

[{1115337740}]***Available display mode : [1280 , 960 , 16 , 60]

[{1115337740}]***Available display mode : [1280 , 960 , 16 , 75]

[{1115337740}]***Available display mode : [1280 , 1024 , 16 , 60]

[{1115337740}]***Available display mode : [1280 , 1024 , 16 , 75]

[{1115337740}]***[TestObjectManager--getDriver]--testCaseId:basicPerformance_addTwoRowsComponent

[{1115337740}]***basicPerformance_addTwoRowsComponent[TearDown]====afterMethod : url=https://test.com/

[{1115337740}]***basicPerformance_addTwoRowsComponent[TearDown]====afterMethod :basicPerformance_addTwoRowsComponent

FAILED CONFIGURATION: @BeforeMethod beforeTest(org.testng.TestRunner@29360691, public void com.morningstar.pa.tests.BasicPerformanceTest.basicPerformance_addTwoRowsComponent(org.testng.ITestContext,java.lang.reflect.Method) throws java.lang.Exception)
java.lang.UnsupportedOperationException: Cannot change display mode

  

[Selenium] Java代码获取,设置屏幕分辨率的更多相关文章

  1. [Selenium] Java代码获取屏幕分辨率

    import java.awt.Dimension; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java. ...

  2. 转--Android如何在java代码中设置margin

    ========  3 在Java代码里设置button的margin(外边距)? 1.获取按钮的LayoutParams LinearLayout.LayoutParams layoutParams ...

  3. [C# 开发技巧系列]如何动态设置屏幕分辨率

    首先,大家应该明确,现在没有可用的API来给我们动态地设置屏幕分辨率,我们要实现这个需求,我们只能在C#程序中调用Win32 API 函数来解决这个问题的,这里用C#代码调用Win32 API 就涉及 ...

  4. C#如何动态设置屏幕分辨率

    C#如何动态设置屏幕分辨率 作者:Learning hard 这篇文章主要为大家详细介绍了C#动态设置屏幕分辨率的方法,我们可以使用Screen类设置屏幕分辨率,感兴趣的小伙伴们可以参考一下 下面就不 ...

  5. android中在java代码中设置Button按钮的背景颜色

    android中在java代码中设置Button按钮的背景颜色 1.设置背景图片,图片来源于drawable: flightInfoPanel.setBackgroundDrawable(getRes ...

  6. 用JAVA代码获取Weblogic配置的JNDI 数据源连接

    第一步:生成与JDK版本对应的weblogicjar,利用cmd 进入到weblogic_home 路径下进入到server/lib目录,然后运行  JDK  1.6 命令 "java -j ...

  7. java代码获取客户端的真实ip

    java代码获取客户端的真实ip protected String getIpAddr(HttpServletRequest request) { String ip = request.getHea ...

  8. Ubuntu设置屏幕分辨率

    Ubuntu设置屏幕分辨率 原创 2016年10月14日 13:01:24 14900 在虚拟机装好Ubuntu,进入系统分辨率是800*600,打开显示界面设置下分辨率,设置完怎么也选不上应用,于是 ...

  9. 乌班图 之 设置镜像服务器 、设置屏幕分辨率QAQ

    设置镜像服务器 Ubuntu 中的大部分软件安装都是用apt命令,从Ubuntu的服务器上直接安装的. 但是国外你懂的网速是硬伤,因此要搞个镜像服务器,内容当然都是一样的咯. 第一步:进入系统设置 第 ...

随机推荐

  1. spring-security-4 (1)介绍

    一.什么是spring security? spring security是基于spring开发的为JavaEE企业级应用提供安全服务的框架.安全服务主要是指 认证(Authentication)和  ...

  2. 1106 1014 C语言文法定义与C程序的推导过程 冒泡程序语法树

  3. Oracle单表去重复(一)

    去重有两层含义,一:是记录完全一样:二:是符合一定条件的认为是重复. 根据表的数量,去重可划分为:单表去重和多表关联去重.   对于去重,一般最容易想到的是用distinct,而distinct只能对 ...

  4. linux Posix 信号量 二

    一.Posix信号量 1.Posix信号量分为两种: 1.   有名信号量:使用Posix IPC名字标识(有名信号量总是既可用于线程间的同步,又可以用于进程间的同步) 2.   内存信号量:存放在共 ...

  5. Linux下搭建企业共享目录方案之------samba

    Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通 ...

  6. Solr Facet 统计查询

    一)概述 Facet是solr的高级搜索功能之一,可以给用户提供更友好的搜索体验.在搜索关键字的同时,能够按照Facet的字段进行分组并统计.例如下图所示,你上淘宝,输入“电脑”进行搜索,就会出现品牌 ...

  7. application/json 和 application/x-www-form-urlencoded的区别

    public static string HttpPost(string url, string body) { //ServicePointManager.ServerCertificateVali ...

  8. Service Mesh扫盲

    原文:http://www.infoq.com/cn/news/2017/12/why-service-mesh 摘要: 对 Service Mesh 的理解?它的出现最终是为了解决什么问题? Ser ...

  9. tesseract-ocr训练方法

    tesseract-ocr有2和3两个版本,不同版本训练方法稍有不同. 第3版本的训练方法官版教程在这里:TrainingTesseract3 第2版的训练方法官版教程在这里:TrainingTess ...

  10. leetcode119

    public class Solution { public IList<int> GetRow(int rowIndex) { List<List<int>> l ...