Re: setLookAndFeel problem
On Feb 14, 11:20 pm, Lew <no...@lewscanon.com> wrote:
How did you decide that it didn't work? To rephrase, precisely what st=
eps did
you use to verify your conclusion?
--
Lew
the same way i have done above worked for my other programes.
please have a look at the below one. it works as expected.
import java.awt.event.ActionListener;
import javax.swing.JFrame;
/**
*
* @author arshad
*/
import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class Beeper extends JPanel implements ActionListener {
JButton button;
public Beeper(){
super(new BorderLayout());
themes();
button=new JButton("Click Me");
button.setPreferredSize(new Dimension(200,80));
add(button,BorderLayout.CENTER);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Toolkit.getDefaultToolkit().beep();
}
//
// create the Gui and show it. for thread safety,
// this method should be invoded from the evennt
dispatching thread
private static void createAndShowGUI(){
//create and set up the window.
JFrame frame =new JFrame("Beeper");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//create and set up the content pane
JComponent newContentPane=new Beeper();
newContentPane.setOpaque(true); //content pane must be opaqu
frame.setContentPane(newContentPane);
//Display the window
frame.pack();
frame.setVisible(true);
}
public void themes(){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception e){
System.out.println("error");
}
}
public static void main(String arg[]){
//schedule a job for the even-dispatchin thread
//creating and shwoing this applications GUI
javax.swing.SwingUtilities.invokeLater(new Runnable(){ public
void run() { createAndShowGUI();}});
}
}
thank you very much.