首页 > 系统相关 >Java eclipse中shell窗口怎么居中显示

Java eclipse中shell窗口怎么居中显示

时间:2023-11-06 12:04:32浏览次数:26  
标签:shell Java int eclipse height width getBounds 屏幕

protected void createContents() {
        shell = new Shell();
        shell.setSize(800, 600);
        shell.setText(title);

        int width=shell.getDisplay().getBounds().width;  // 找到createContents这个方法,得到屏幕的宽度。
        int height=shell.getDisplay().getBounds().height;  // 在这个方法中,得到屏幕的高度。
        // 得到屏幕的宽高度减去shell窗口的宽度和高度,除以2得到窗口的左上角坐标。
        int x=(width-shell.getBounds().width)/2;
        int y=(height-shell.getBounds().height)/2;
        shell.setLocation(x, y);}

标签:shell,Java,int,eclipse,height,width,getBounds,屏幕
From: https://blog.51cto.com/emanlee/8203521

相关文章

  • Eclipse: export project such that Windows and Mac can both run it (SWT)
     [root@localhostaimin]#java-jarTASTS.jarExceptioninthread"main"java.lang.UnsatisfiedLinkError:CouldnotloadSWTlibrary.Reasons:   noswt-win32-4930r7injava.library.path   noswt-win32injava.library.path   Can'tloadlibr......
  • Java程序如何生成Jar 执行文件
     EclipseIDE      ......
  • Java jar: A JNI error has occurred, please check your installation and try again
    java-verion和javac-version版本不一致 E:\temp\eclipseWorkSpace>java-jarTASTS.jarExceptioninthread"main"java.lang.NoClassDefFoundError:org/eclipse/swt/widgets/DecorationsCausedby:java.lang.ClassNotFoundException:org.eclipse.swt.widge......
  • 切换JDK版本时修改JAVA_HOME环境变量不生效
     Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Environment           解决方法: (1)检查环境变量Path;(2)删除java.exe,javaw.exe,javaws.exe 在修改JDK的安装目录的情况下会出现失效的时候,因为jdk在安装的时候自己在path中添加了......
  • Java去除字符串中空格的方法详解
    1、方法str.trim();str.replace("","");str.replaceAll("","");str.replaceAll("+","");str.replaceAll("\\s*","");\\s*可以匹配空格、制表符、换页符等空白字符的其中任意一个。 2、示例packagetest;publicc......
  • JAVA SWT的MessageBox对话框
    Referencedjar:org.eclipse.swt.win32.win32.x86_64_3.113.0.v20191204-0601.jar importorg.eclipse.swt.widgets.MessageBox; SWT有不同类型的对话框。有些对话框具有特殊的属性。MessageBoxmessageBox=newMessageBox(shell,SWT.OK|SWT.CANCEL);if(messageBox.open(......
  • 模拟攻击beescms框架网站,并且一步一步渗透测试,上传shell,连接蚁剑,拿到对方网站根目录
    打开网站发现它是beescms框架搭建的网站,一言不合直接用webpathbrute扫描发现了管理员登录页面尝试任意用户名密码登录发现不太行,直接暴力破解,先burp抓数据包发现有4个参数有user,password,code,submit,把submit=ture修改为submit=false验证码就不会刷新了就是284c。接下来......
  • java中的重排序和volatile关键字
    一、内存模型基础1、内存模型描述的是程序中各变量(线程共享变量)的访问规则,以及在实际计算机系统中将变量存储到内存和从内存读取出变量这样的低层细节。2、Jvm系统中存在一个主内存(MainMemory或JavaHeapMemory),Java中所有变量都储存在主存中,对于所有线程都是共享的。3、每......
  • javascript中的时间格式化的方法
     javascript中的时间格式化的方法 Date.prototype.format=function(format){varo={"M+":this.getMonth()+1,//month"d+":this.getDate(),//day"h+":this.getHours(),//hour&quo......
  • 探索 Java 8 中的 Stream 流:构建流的多种方式
    当我们处理集合数据时,往往需要对其进行各种操作,如过滤、映射、排序、归约等。在Java8中引入的Stream流为我们提供了一种更加简洁和灵活的方式来处理数据。上述情况都是流对集合进行操作的,但是对于流的创建操作还是不太了解,其实流的创建不止是使用集合进行创建,还可以基于值、数......