Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: lookandfeel() cannot be applied to JFrame?

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy lookandfeel() cannot be applied to JFrame?

    Hi,
    im testing a simple code for an ActionLIstener event for a button.
    the expected outcome with the functionality of the button is ok.
    but i couldn't set the *theme* get displayed.
    i.e. the method calling lookAndFeel() does not seems to work.
    any help would be greately appreciable.


    thank you very much

    [FONT=Courier, Monospaced]import java.awt.*; 
     import java.awt.event.*; 
     import javax.swing.SwingUtilities; 
     import javax.swing.UIManager; 
     [/FONT]
    [FONT=Courier, Monospaced]public class AL extends Frame implements WindowListener,ActionListener 
     { 
     [/FONT]
    [FONT=Courier, Monospaced]        TextField text = new TextField(20); 
             Button b; 
             private int numClicks = 0; 
     [/FONT]
    [FONT=Courier, Monospaced]        public static void main(String[] args) { 
     [/FONT]
    [FONT=Courier, Monospaced]                AL myWindow = new AL("My first window"); 
                     myWindow.setSize(350,100); 
                     myWindow.setVisible(true); 
             } 
     [/FONT]
    [FONT=Courier, Monospaced]        public AL(String title) { 
     [/FONT]
    [FONT=Courier, Monospaced]                super(title); 
                     setLayout(new FlowLayout()); 
                     addWindowListener(this); 
             lookAndFeel(); 
     [/FONT]
    [FONT=Courier, Monospaced]                b = new Button("Click me"); 
                     add(b); 
                     add(text); 
                     b.addActionListener(this); 
             } 
     [/FONT]
    [FONT=Courier, Monospaced]    public void lookAndFeel(){ 
                     try{ 
                     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
                     SwingUtilities.updateComponentTreeUI(this); 
                     }catch(Exception e){ 
                             System.out.println("errr"); 
                     } 
             } 
     [/FONT]
    [FONT=Courier, Monospaced]        public void actionPerformed(ActionEvent e) { 
                     numClicks++; 
                     text.setText("Button Clicked " + numClicks + " times"); 
     [/FONT]
    [FONT=Courier, Monospaced]        } 
     [/FONT]
    [FONT=Courier, Monospaced]        public void windowClosing(WindowEvent e) { 
                     dispose(); 
                     System.exit(0); 
             } 
     [/FONT]
    [FONT=Courier, Monospaced]        public void windowOpened(WindowEvent e) {} 
             public void windowActivated(WindowEvent e) {} 
             public void windowIconified(WindowEvent e) {} 
             public void windowDeiconified(WindowEvent e) {} 
             public void windowDeactivated(WindowEvent e) {} 
             public void windowClosed(WindowEvent e) {} [/FONT]

    i heard that lookandfeel() cannot be applied to JFrame. but for the below program the lookandfeel() works well.

    [FONT=Courier, Monospaced]import javax.swing.*; 
     import java.awt.*; 
     /** 
      * 
      * @author arshad 
      */ 
     public class ProgressMonitor extends JFrame{ 
     [/FONT]
    [FONT=Courier, Monospaced]    JProgressBar current; 
         JTextArea out; 
         JButton find; 
         Thread runner; 
         int num=0; 
     [/FONT]
    [FONT=Courier, Monospaced]    public ProgressMonitor() { 
     [/FONT]
    [FONT=Courier, Monospaced]        super("Progress Monitor"); 
             Dimension 
     d=java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 
             setSize(d); 
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
             setLookAndFeel(); 
     [/FONT]
    [FONT=Courier, Monospaced]//        setSize(205,68); 
             setLayout(new FlowLayout()); 
             current=new JProgressBar(0,2000); 
             current.setValue(0); 
             current.setStringPainted(true); 
             JLabel label=new JLabel("You have been fooled!, Your machine 
     is being formatted"); 
             JPanel panel=new JPanel(); 
     [/FONT]
    [FONT=Courier, Monospaced]//        panel.add(sld); 
     [/FONT]
    [FONT=Courier, Monospaced]        panel.add(label); 
             panel.add(current); 
             add(panel); 
             setVisible(true); 
             ///add(current); 
     [/FONT]
    [FONT=Courier, Monospaced]//        pack(); 
     [/FONT]
    [FONT=Courier, Monospaced]    } 
     [/FONT]
    [FONT=Courier, Monospaced]    private void setLookAndFeel(){ 
             try{ 
     [/FONT]
    [FONT=Courier, Monospaced]UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
                 SwingUtilities.updateComponentTreeUI(this); 
             }catch(Exception e){ 
                 System.out.println("errorrrr"); 
             } 
         } 
     [/FONT]
    [FONT=Courier, Monospaced]    public void iterate(){ 
             while(num<2000){ 
                 current.setValue(num); 
                 try{ 
                     Thread.sleep(1000); 
                 }catch(InterruptedException e){} 
                 num+=95; 
     [/FONT]
    [FONT=Courier, Monospaced]        } 
     [/FONT]
    [FONT=Courier, Monospaced]    } 
     [/FONT]
    [FONT=Courier, Monospaced]public static void main(String arg[]){ 
         ProgressMonitor frame=new ProgressMonitor(); 
         frame.setVisible(true); 
         frame.iterate(); [/FONT]


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: lookandfeel() cannot be applied to JFrame?

    You certainly can change the look and feel of the JFrame. See How to Make Frames (Main Windows).

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    emigrant (February 15th, 2010)

Similar Threads

  1. Inputs not being applied.
    By Norflok669 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 15th, 2010, 01:25 AM
  2. need help with ActionListener,JPanel,JFrame
    By amahara in forum AWT / Java Swing
    Replies: 5
    Last Post: February 3rd, 2010, 01:40 PM
  3. JFrame help
    By Uden in forum AWT / Java Swing
    Replies: 0
    Last Post: August 14th, 2009, 02:37 PM
  4. [SOLVED] Facing java error "cannot be applied to (java.lang.String)"
    By tazjaime in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2009, 11:19 AM
  5. Replies: 3
    Last Post: February 26th, 2009, 05:21 PM