Java methods for the help class UIHelper of UI appearance settings

Source: Internet
Author: User

Public class UIHelper {

// Set center display in the window
Public static void setCenter (Component comp ){
Toolkit toolkit = Toolkit. getdefatooltoolkit ();
Dimension screenSize = toolkit. getScreenSize ();

Int x = (screenSize. width-(int) comp. getPreferredSize (). getWidth ()/2;
Int y = (screenSize. height-(int) comp. getPreferredSize (). getHeight ()/2;

Comp. setLocation (x, y );
}

/* Set window maximization. The window object is JFrame */
Public static void setWinMax (JFrame frame)
{
Frame. setExtendedState (javax. swing. JFrame. MAXIMIZED_BOTH );
}

 

/* Set window maximization. When the window object is JPanel */
Public static void setMaxSize (JPanel ){
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment. getLocalGraphicsEnvironment ();
// Get maximum window bounds
Rectangle maximumWindowBounds = graphicsEnvironment. getMaximumWindowBounds ();
Dimension activeSize = new Dimension (maximumWindowBounds. width, maximumWindowBounds. height );
Panel. setPreferredSize (activeSize );
}

/* Check whether the input value of the interface is blank */
Public static boolean isEmpty (String inputValue ){
If (inputValue = null | "". equals (inputValue. trim ()))
Return true;
Else
Return false;
}

 

/* Make the java gui use the interface style of the previous operating system, so that the java interface is no longer ugly */

Public static void setUILookAndFeel (){
Try {
UIManager. setLookAndFeel (UIManager. getSystemLookAndFeelClassName ());
} Catch (ClassNotFoundException ex ){
Logger. getLogger (SysUtil. class. getName (). log (Level. SEVERE, null, ex );
} Catch (InstantiationException ex ){
Logger. getLogger (SysUtil. class. getName (). log (Level. SEVERE, null, ex );
} Catch (IllegalAccessException ex ){
Logger. getLogger (SysUtil. class. getName (). log (Level. SEVERE, null, ex );
} Catch (UnsupportedLookAndFeelException ex ){
Logger. getLogger (SysUtil. class. getName (). log (Level. SEVERE, null, ex );
}

}

}

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.