Swing applications can be easy to switch between open source Look&&feel, but the problem comes when you switch the application to the default or JDK-like appearance under open source. Not without the title bar, that is, the appearance of the title bar has not changed, with the system window decoration. These are caused by adding such a code to the main method when the application starts:
Jframe.setdefaultlookandfeeldecorated (TRUE);
The solution to this problem is to dispose of the original JFrame first, then a JFrame in new, so that the original frame to point to the new JFrame. Not much to say, look at the code more intuitive, the core code is as follows:
Initialization application, the Initcomponents () method is generated by the NetBeans IDE and is not posted.
private static JFrame config;
Private Rectangle savedbounds;
/** creates new form Config */public
Skinchangedemo () {
initcomponents ();
Public
Skinchangedemo (Boolean decor) {
setundecorated (decor);
Initcomponents ();
}
Here's the core code:
private void Saharabuttonactionperformed (Java.awt.event.ActionEvent evt) {
TODO Add your handling code here:lookandfeel old = Uimanager.getlookandfeel ();
Substanceskin skin = new Saharaskin ();
if (old instanceof Substancelookandfeel) {Substancelookandfeel.setskin (skin);
else {//If the appearance is not substance, switch to substance appearance changskin (skin); }} private void Nimbusbuttonactionperformed (Java.awt.event.ActionEven T evt) {try {uimanager.setlookandfeel (new Nimbuslookand
Feel ());
Savedbounds = GetBounds ();
Dispose ();
config = null;
Config = new Skinchangedemo (false);
Config.setbounds (Savedbounds);
Config.setvisible (TRUE); catch (Unsupportedlookandfeelexception ex) {LoGger.getlogger (SkinChangeDemo.class.getName ()). log (Level.severe, NULL, ex);
} swingutilities.updatecomponenttreeui (this); } private void businessbuttonactionperformed (Java.awt.event.ActionEvent ev
T) {Lookandfeel old = Uimanager.getlookandfeel ();
Substanceskin skin = new Businessskin ();
if (old instanceof Substancelookandfeel) {Substancelookandfeel.setskin (skin);
else {//If the appearance is not substance, switch to substance appearance changskin (skin);
}/** * is used to make the interface of a substance appearance the substance appearance.
* @param skin */private void Changskin (Substanceskin skin) {savedbounds = GetBounds ();
Dispose ();
Config = new Skinchangedemo (true); Config.getrootpane (). Setwindowdecorationstyle (Jrootpane.frame); This is the key code, see your own API Experience bar Config.setbounDS (Savedbounds);
Maintain the change of the skin when the position is Substancelookandfeel.setskin (skin);
Config.setvisible (TRUE);
Config.getrootpane (). UpdateUI ();
Swingutilities.updatecomponenttreeui (this); }