Swing skill summary, PS: recommended Java2HTML

xiaoxiao2021-03-06  41

All mentioned Swing skills are all in one class, which is convenient to call. In addition, finally find a good java2html: http://gnuwin32.SourceForge.Net/packages/src-highlite.htm to see the effect of the web page, very good .

/ *

* Created on 2005-2-19

* /

Package Net.9cbs.dyhml.util;

Import java.awt.component;

Import java.awt.cursor;

Import java.awt.dimension;

Import java.awt.font;

Import java.awt.frame;

Import Java.awt.Image;

Import java.awt.point;

Import java.awt.toolkit;

Import java.awt.window;

Import java.util.enumeration;

Import javax.swing.jdialog;

Import javax.swing.jframe;

Import javax.swing.jrootpane;

Import javax.swing.lookandfeel;

Import javax.swing.swingutilities;

Import javax.swing.uimanager;

Import javax.swing.plaf.fontuiresource;

/ **

* Provide a static method for AWT, SWING

*

* @Author Viruscamp

* /

Public class swingutil {

/ **

* The default java.awt.toolkit used by the methods used in this class

* /

Public Static Final Toolkit Toolkit = Toolkit.getDefaultToolkit ();

/ **

* Fully screen Window, valid for Window, Frame, Dialog, Jwindow, JFrame, JDialog

* @Param Window full screening Window

* @see Window, Frame, Dialog, Jwindow, Jframe, JDIALOG

* /

Public static void setsizefullofscreen (window window) {

Dimension Screensize = Toolkit.getscreensize ();

Window.setbounds (0, 0, Screensize.width, Screensize.height);

}

/ **

* Set Window in the middle of the screen, valid for Window, Frame, Dialog, Jwindow, JFrame, JDialog

* @Param Window Window set in the middle of the screen

* @see Window, Frame, Dialog, Jwindow, Jframe, JDIALOG

* /

Public Static Void SettoscreenCenter (Window Window) {

Dimension Screensize = Toolkit.getscreensize ();

Dimension Windowsize = window.getsize ();

Windowsize.height> Screensize.height)

Windowsize.height = Screensize.height;

IF (Windowsize.Width> Screensize.width)

Windowsize.width = Screensize.width; Window.SetLocation ((Screensize.width - Windowsize.width) / 2,

Screensize.height - windowsize.height / 2);

}

/ **

* Set global font

* @Param font global font

* /

Public Static Void InitglobalFontSetting (font font) {

Fontuiresource Fontres = New Fontuiresource (font);

FOR (Enumeration Keys = UIManager.getDefaults (). Keys (); Keys

.hasmorelements ();

Object key = keys.nextelement ();

Object value = uimanager.get (key);

Value InstanceOf Fontuiresource

UIManager.put (key, fontres);

}

}

/ **

* Set the cursor on Component (CURSOR)

* @param c Sets the cursor on this Component (CURSOR)

* @Param Image Setting Cursor (CURSOR) pattern

* /

PUBLIC Static Void SetCursor (Component C, Image Image) {

Cursor Cursor = Toolkit

.createcustomcursor (Image, New Point (0, 0), NULL);

C.SETCURSOR (CURSOR);

}

/ **

* Set the global LookandFeel, this LookAndfeel is used after this LookandFeel

* @Param lafstr Setting LookandFeel

* @Return 0: Set success, 1: Set failure

* /

Public Static int setglobal {String Lafstr) {

Try {

UIManager.SetLookAndfeel (lafstr);

Return 0;

} catch (exception e) {

Return 1;

}

}

/ **

* JFRAME established later, whether JDIALOG is decorated using LookandFeel window (title bar, border, etc.)

* /

Private static boolean isundecorated = false;

/ **

* Returns the JFRAME established after this, is JDIALOG to use the window decoration of the LookandFeel (title bar, border, etc.)

* @Return's JFRAME, JDIALOG is decorated using the window decoration of the LookandFeel (title bar, border, etc.)

* /

Public static boolean isundecorated () {

Return isundecorated;

}

/ **

* Set this subsequent JFRAME, JDialog is decorated with the window of the LookandFeel (title bar, border, etc.)

* @Param Whether JFRAME, JDialog is decorated with the window decoration of the LookandFeel (title bar, border, etc.)

* /

Public static void setundecorated (boolean undecorated) {

Lookandfeel laf = uimanager.getlookAndfeel ();

Swingutil.isundecorated = undecorated;

JFrame.SetDefaultLookandFeelDecorated (undecorated

&& laf.getsupportswindowdecorations ()); JDIALOG.SETDEFAULTLOOKANDFEELDECORATED (undecorated

&& laf.getsupportswindowdecorations ());

}

/ **

* Set whether JFRAME is decorated using the window of the LookandFeel (title bar, border, etc.)

* @Param Whether to use the window decoration of the LookandFeel (title bar, border, etc.)

* /

Public Static Void Setundecoated (JFrame Frame, Boolean undecorated) {

Frame.ISPLAYABLE ()) frame.dispose ();

Frame.setundecoated (undecorated && uimanager.getlookandfeel (). getsupportswindowdecorations ());

JRootpane jrootpane = frame.getrootpane ();

JRootpane.SetWindowDecorationStyle (JRootpane.GetWindowDecorationStyle ());

Frame.ISPLAYABLE ()) frame.show ();

}

/ **

* Set whether JDIALOG is decorated using the window of the LookandFeel (title bar, border, etc.)

* @Param Whether to use the window decoration of the LookandFeel (title bar, border, etc.)

* /

Public Static Void Setundecoated (JDIALOG DIALOG, BOOLEAN undecorated) {

IF (Dialog.ISDisPlayable ()) Dialog.dispose ();

Dialog.setundecoated (undecorated && uimanager.getlookandfeel (). getsupportswindowdecorations ());

JRootpane jrootpane = dialog.getrootpane ();

JRootpane.SetWindowDecorationStyle (JRootpane.GetWindowDecorationStyle ());

IF (Dialog.IsdisPlayable ()) Dialog.show ();

}

/ **

* Update all JFrames for this program to be established, LookandFeel

* /

Public static void updateui () {

Frame [] frames = frame.getframes ();

For (INT i = 0; i

UpdateUi (frames [i]);

}

/ **

* Update your COMPONENT LOOKANDFEEL

* @Param Target Operation Operation

* /

Public static void updateui (Component Target) {

Target InstanceOf Jframe

Updateui (JFrame) Target, isundecoated;

Target InstanceOf JDialog

Updateui (JDIALOG) Target, isundecorated;

Swingutilities.UpdateComponentTreeui (Target);

}

/ **

* Update JFrame's LookandFeel, change the border of JFrame, title

* @Param Frame operation object

* @Param undecoated Whether to use the window decoration of the LookandFeel (title bar, border, etc.)

* /

Public static void updateui (jframe frame, boolean undecorated) {setundecorad (frame, undecorated);

Swingutilities.UpdateComponentTreeui (frame);

}

/ **

* Update JDialog's LookandFeel, change the border of JDialog, title

* @Param Dialog Operation object

* @Param undecoated Whether to use the window decoration of the LookandFeel (title bar, border, etc.)

* /

Public Static Void UpdateUi (JDIALOG DIALOG, BOOLEAN undecorated) {

Setundecoated (Dialog, undecorated);

Swingutilities.UpdateComponentTreeui (Dialog);

}

}

转载请注明原文地址:https://www.9cbs.com/read-56315.html

New Post(0)