Java: 在不同windows主題下,JFrame視窗設定最佳高度的解決方案

來源:互聯網
上載者:User

標籤:

//設定視窗的大小,無論使用怎樣的windows主題,都能靈活的應對,顯示合適的視窗大小,一定要在JFrame.setVisible(true)之前調用,//替代傳統的frame.setSize(width,height); public static void setSize(JFrame frame, int width, int height) {  //一定要在JFrame顯示之前調用  frame.pack();  //在預設的setResizable(true); 情況下,titleDefaultHeight = 27,但如果 setResizable(false); titleDefaultHeight = 25  int titleDefaultHeight = frame.isResizable() ? 27 : 25; //預設開發階段使用windows 經典主題,標題列高度= 27   int containerHeight = frame.getContentPane().getHeight();  //System.out.println("containerHeight:" + containerHeight); //windows 經典主題或xp主題下 = 1  //int rootPaneHeight = frame.getRootPane().getHeight(); //取得的高度和container的高度是一樣的  int frameHeight = frame.getHeight();  //System.out.println("frameHeight:" + frameHeight); //windows經典主題下= 28, windows xp 主題下 = 33    int titleHeight = frameHeight - containerHeight; //這裡就可以得到當前標題列的實際高度  if (titleHeight > titleDefaultHeight)  {   int h = titleHeight - titleDefaultHeight; //得到當前使用的主題,標題列 - 經典主題下的標題列高度 = 差值        frame.setSize(width, height + h); //最終確定視窗的高度  }  else  {   frame.setSize(width, height);  } }

 

Java: 在不同windows主題下,JFrame視窗設定最佳高度的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.