Java tutorial
/** * ===================================================================== * Copyright (C) 2009 Shawn E. Gano * * This file is part of JSatTrak. * * JSatTrak is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JSatTrak is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with JSatTrak. If not, see <http://www.gnu.org/licenses/>. * ===================================================================== */ package jsattrak.gui; import com.jgoodies.looks.plastic.PlasticLookAndFeel; import com.jgoodies.looks.plastic.PlasticXPLookAndFeel; import com.jgoodies.looks.plastic.theme.ExperienceBlue; import com.jgoodies.looks.plastic.theme.ExperienceGreen; import com.jgoodies.looks.plastic.theme.Silver; import java.awt.Window; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.UIManager; import jsattrak.utilities.LafChanger; /** * * @author sgano */ public class LookAndFeelJDialog extends javax.swing.JDialog { JFrame parent; /** Creates new form LookAndFeelJDialog */ public LookAndFeelJDialog(JFrame parent, boolean modal) { super(parent, modal); initComponents(); this.parent = parent; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jButton10 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); LafList = new javax.swing.JList(); jButton7 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Look and Feel Selector"); jButton1.setText("Nimbus (java 1.6.10)"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Metal"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("System"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setText("Plastic - Experience Blue"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton5.setText("Plastic - Experience Green"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton6.setText("Plastic - Silver"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); jButton9.setText("Plastic - XP"); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); jButton10.setText("Motif"); jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt); } }); LafList.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Business", "BusinessBlueSteel", "BusinessBlackSteel", "Creme", "CremeCoffee", "Sahara", "Moderate", "OfficeSilver2007", "OfficeBlue2007", "Nebula", "NebulaBrickWall", "Autumn", "MistSilver", "MistAqua", "RavenGraphite", "RavenGraphiteGlass", "Raven", "Magma", "ChallengerDeep", "EmeraldDusk" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); jScrollPane1.setViewportView(LafList); jButton7.setText("Substance Look and Feel"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton10) .addGap(9, 9, 9).addComponent(jButton4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton9) .addGap(35, 35, 35) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton7) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); for (Window window : Window.getWindows()) { SwingUtilities.updateComponentTreeUI(window); } SwingUtilities.updateComponentTreeUI(parent); // needs to be applied twice for some reason UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); for (Window window : Window.getWindows()) { SwingUtilities.updateComponentTreeUI(window); } SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) } catch (Exception ex) { //System.out.println("Sorry no Nimbus LookAndFeel needs java 6u10 or higher!"); //ex.printStackTrace(); } LafChanger.changeLaf(parent, "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); LafChanger.changeLaf(parent, "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); // needs to run twice? (but it isn't) }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed LafChanger.changeLaf(parent, "javax.swing.plaf.metal.MetalLookAndFeel"); // try // { // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); // SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) // } // catch(Exception ex) // { // } }//GEN-LAST:event_jButton2ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed LafChanger.changeLaf(parent, UIManager.getSystemLookAndFeelClassName()); // try // { // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) // } // catch(Exception ex) // { // } }//GEN-LAST:event_jButton3ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed //LafChanger.changeLaf(parent, "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); try { PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue()); PlasticLookAndFeel.setTabStyle("Metal"); // makes tabes look much better UIManager.setLookAndFeel(new PlasticLookAndFeel()); SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) } catch (Exception ex) { } }//GEN-LAST:event_jButton4ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // LafChanger.changeLaf(parent, "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); try { PlasticLookAndFeel.setPlasticTheme(new ExperienceGreen()); PlasticLookAndFeel.setTabStyle("Metal"); // makes tabes look much better UIManager.setLookAndFeel(new PlasticLookAndFeel()); SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) } catch (Exception ex) { } }//GEN-LAST:event_jButton5ActionPerformed private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed //LafChanger.changeLaf(parent, "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); try { PlasticLookAndFeel.setPlasticTheme(new Silver()); PlasticLookAndFeel.setTabStyle("Metal"); // makes tabes look much better UIManager.setLookAndFeel(new PlasticLookAndFeel()); SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) } catch (Exception ex) { } }//GEN-LAST:event_jButton6ActionPerformed private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed //LafChanger.changeLaf(parent, "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); try { UIManager.setLookAndFeel(new PlasticXPLookAndFeel()); SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) } catch (Exception ex) { System.err.println("err:" + ex.toString()); } }//GEN-LAST:event_jButton9ActionPerformed private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed LafChanger.changeLaf(parent, "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); // try // { // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); // // SwingUtilities.updateComponentTreeUI(parent); // apply look and feel over current L&F (otherwise nimbus shows up in correctly) // } // catch(Exception ex) // { // System.err.println("err:"+ex.toString()); // } }//GEN-LAST:event_jButton10ActionPerformed private void jButton7ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton7ActionPerformed {//GEN-HEADEREND:event_jButton7ActionPerformed String laf = "org.jvnet.substance.skin.Substance" + LafList.getSelectedValue().toString() + "LookAndFeel"; LafChanger.changeLaf(parent, laf); }//GEN-LAST:event_jButton7ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { LookAndFeelJDialog dialog = new LookAndFeelJDialog(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JList LafList; private javax.swing.JButton jButton1; private javax.swing.JButton jButton10; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JButton jButton9; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }