Java: A solution that sets the best height for jframe windows under different Windows themes

Source: Internet
Author: User

//setting the size of the window, regardless of the Windows theme you use, is flexible, showing the appropriate window size, and must be called before jframe.setvisible (true) .//Alternative to traditional frame.setsize (width,height);  Public Static voidSetSize (JFrame frame,intWidthintheight) {  //be sure to call before the JFrame displayFrame.pack (); //in the default setresizable (true); titledefaultheight = 27, but if setresizable (false); titledefaultheight =  intTitledefaultheight = Frame.isresizable ()? 27:25;//The default development stage uses the Windows Classic theme, title bar height =  intContainerheight =Frame.getcontentpane (). GetHeight (); //System.out.println ("containerheight:" + containerheight);//Windows Classic theme or XP under theme = 1//int rootpaneheight = Frame.getrootpane (). GetHeight ();//The height obtained is the same as the height of the container.  intFrameheight =frame.getheight (); //System.out.println ("frameheight:" + frameheight);//Windows Classic Theme under =, Windows XP under topic =  intTitleheight = Frameheight-containerheight;//Here you can get the actual height of the current title bar  if(Titleheight >titledefaultheight) {   inth = titleheight-titledefaultheight;//get the currently used theme, title bar-title bar height under Classic theme = DifferenceFrame.setsize (width, height + h);//Finalize The height of the window  }  Else{frame.setsize (width, height); } }

Java: A solution that sets the best height for jframe windows under different Windows themes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.