Skip to main content

Nimbus problems

No replies
GenJava
Offline
Joined: 2011-10-13
Points: 0

Hi all

The following code shows Nimbus problems:

import javax.swing.*;

import javax.swing.UIManager.*;

import java.awt.*;

import java.awt.event.*;

class Nimbus

{

public static void main (String...args)

{

JFrame f=new JFrame ("main");

JButton b1=new JButton("Nimbus"), b2=new JButton("Others"), b3=new JButton("disabled");

JToolBar tb=new JToolBar(SwingConstants.HORIZONTAL);

b1.addActionListener(new bc(f));

b2.addActionListener(new bc(f));

b3.setEnabled(false);

tb.add(new JButton("notDisabled"));

tb.add(b3);

tb.add(new JTextField(10));

tb.add(Box.createHorizontalGlue());

tb.add(new JLabel("this is a label"));

f.add(b1,BorderLayout.PAGE_START);

f.add(tb,BorderLayout.CENTER);

f.add(b2,BorderLayout.PAGE_END);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.pack();

f.setVisible(true);

}

public static class bc implements ActionListener

{

JFrame f;

public bc(JFrame f)

{

this.f=f;

}

public void actionPerformed(ActionEvent e)

{

String laf=null;

if ( ((JButton)e.getSource()).getText().equals("Nimbus") )

laf = GetLAFName ( "Nimbus" );

else

if ( ((JButton)e.getSource()).getText().equals("Others") )

laf = GetLAFName ( "Windows" );

try{

UIManager.setLookAndFeel (laf);

SwingUtilities.updateComponentTreeUI(f);

}catch(Throwable t){System.out.println(t);}

}

}

private static String GetLAFName(String Name)

{

for (UIManager.LookAndFeelInfo info:UIManager.getInstalledLookAndFeels())

if(info.getName().equals(Name))

return info.getClassName();

return null;

}

}

Please compile and run the code, click on Nimbus button to watch the label disappear. Also there is no visible difference between enabled and disabled buttons. I saw SwingSet3 demo uses Nimbus with no problems, so what am I doing wrong?

Thank you