Java Reference
In-Depth Information
73
74
add(northPanel, BorderLayout.NORTH ); // add north panel
75
add(southPanel, BorderLayout.SOUTH ); // add south panel
76
77
radio[0].setSelected( true ); // set default selection
78
} // end LookAndFeelFrame constructor
79
80
// use UIManager to change look-and-feel of GUI
81
private void changeTheLookAndFeel( int value)
82
{
83
try // change look-and-feel
84
{
85
// set look-and-feel for this application
UIManager.setLookAndFeel(looks[value].getClassName());
86
87
88
// update components in this application
SwingUtilities.updateComponentTreeUI( this );
89
90
}
91
catch (Exception exception)
92
{
93
exception.printStackTrace();
94
}
95
}
96
97 // private inner class to handle radio button events
98 private class ItemHandler implements ItemListener
99 {
100 // process user's look-and-feel selection
101 @Override
102 public void itemStateChanged(ItemEvent event)
103 {
104 for ( int count = 0 ; count < radio.length; count++)
105 {
106 if (radio[count].isSelected())
107 {
108 label.setText(String.format(
109 "This is a %s look-and-feel" , lookNames[count]));
110 comboBox.setSelectedIndex(count); // set combobox index
111 changeTheLookAndFeel(count); // change look-and-feel
112 }
113 }
114 }
115 } // end private inner class ItemHandler
116 } // end class LookAndFeelFrame
Fig. 22.9 | Look-and-feel of a Swing-based GUI. (Part 3 of 3.)
1
// Fig. 22.10: LookAndFeelDemo.java
2
// Changing the look-and-feel.
3
import javax.swing.JFrame;
4
Fig. 22.10 | Test class for LookAndFeelFrame . (Part 1 of 2.)
Search WWH ::




Custom Search