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 );
}
}
}