import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LookAndFeelDemo extends JFrame { private String strings[] = { "Metal", "Motif", "Windows" }; private UIManager.LookAndFeelInfo looks[]; private JRadioButton radio[]; private ButtonGroup group; private JButton button; private JLabel label; private JComboBox comboBox; public LookAndFeelDemo() { super( "Look and Feel Demo" ); Container c = getContentPane(); JPanel northPanel = new JPanel(); northPanel.setLayout( new GridLayout( 3, 1, 0, 5 ) ); label = new JLabel( "This is a Metal look-and-feel", SwingConstants.CENTER ); northPanel.add( label ); button = new JButton( "JButton" ); northPanel.add( button ); comboBox = new JComboBox( strings ); northPanel.add( comboBox ); c.add( northPanel, BorderLayout.NORTH ); JPanel southPanel = new JPanel(); radio = new JRadioButton[ strings.length ]; group = new ButtonGroup(); ItemHandler handler = new ItemHandler(); southPanel.setLayout( new GridLayout( 1, radio.length ) ); for ( int i = 0; i < radio.length; i++ ) { radio[ i ] = new JRadioButton( strings[ i ] ); radio[ i ].addItemListener( handler ); group.add( radio[ i ] ); southPanel.add( radio[ i ] ); } c.add( southPanel, BorderLayout.SOUTH ); // get the installed look-and-feel information looks = UIManager.getInstalledLookAndFeels(); setSize( 300, 200 ); show(); radio[ 0 ].setSelected( true ); } private void changeTheLookAndFeel( int value ) { try { UIManager.setLookAndFeel( looks[ value ].getClassName() ); SwingUtilities.updateComponentTreeUI( this ); } catch ( Exception e ) { e.printStackTrace(); } } public static void main( String args[] ) { LookAndFeelDemo dx = new LookAndFeelDemo(); dx.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); } private class ItemHandler implements ItemListener { public void itemStateChanged( ItemEvent e ) { for ( int i = 0; i < radio.length; i++ ) if ( radio[ i ].isSelected() ) { label.setText( "This is a " + strings[ i ] + " look-and-feel" ); comboBox.setSelectedIndex( i ); changeTheLookAndFeel( i ); } } } }
15 Comments
Most what i read online is trash and copy paste but i think you offer something different. Keep it like this.
Thknas for sharing. Always good to find a real expert.
Hi, i think that i saw you visited my blog so i came to “return the favour”.I am trying to find things to improve my blog!I suppose its ok to use some of your ideas!!
Good point. I hadn’t tohhugt about it quite that way. π
You made some good points there. I did a search on the topic and found most people agree with you. But it’s human nature for some to disagree. But whatever. They’re in the minority.
This has made my day. I wish all potsnigs were this good.
Hello good Jason ,I am supposed to be a tea and coffee aficionado, completely love the scent and the tingling sensation of tea as the very first thing after getting up. I Guzzle atleast five glasses every single day. By the way nice blog, Have a great day.
You are not the common blog author, man. You definitely have something important to add to the net. Such a good blog. I’ll come back again for more.
I want to thnx for the efforts you have made in composing this blog post. I am hoping the same high-grade blogpost from you in the upcoming as well. In fact your creative writing abilities has inspired me to begin my own blog now. Truly the blogging is spreading its wings quickly. Your write up is a good model of it.
Thanks for sharing. Always good to find a real epexrt.
now in my rss reader)))
thankyou
123inkjets coupon
I dont know what to say. this blog is fantastic. Thats not really a really huge statement, but its all I could come up with after reading this. You know so much about this subject. So much so that you made me want to learn more about it. Your website is my stepping stone, my friend. thanks for the heads up on this subject.
Your answer was just what I nedeed. ItΓβs made my day!
Hi there my chum hip site – really like it. greets
Great blog – like it.