Results 1 to 5 of 5
  1. #1
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default Can you toggle between look and feel, want to make different "themes"

    Can you?

    Or is there some other way to change "themes".


    if not, can anyone help with a lamer "theme"?

    In my GUI I have a method called: theme3()

    that basically uses a loop to change my button backgrounds.

    Java Code:
    public static void theme3(){
    		for (int a = 0; a < 9; a++){
    			for (int b = 0; b < 9; b++){
    				Grid[a][b].setBackground(Color.ORANGE);
    			}
    		}
    	}
    Java Code:
    final JRadioButtonMenuItem three = new JRadioButtonMenuItem("Theme: Third");
    	    three.setSelected(true);
    	    three.addActionListener(new ActionListener(){
    	    	public void actionPerformed(ActionEvent e){
    	    		theme3();
    	    	}
    	    });
    the radio button is in "MenuBar" that extends JMenuBar that is a inner class in my GUI.

    whether I type theme3(); or GUI.theme3(); there isn't any error, the thing is, clicking the button doesn't do anything either.

  2. #2
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    Try calling repaint() on each element after you change its background.

  3. #3
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    no point, tried it anyway.

    when you use setText or setBackground, the button automatically changes, there should be no reason to repaint.

    hear stuff about invalidate and validate, but those aren't working either

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    Hmm, setBackground() works for me...
    Java Code:
       import javax.swing.*;
       import java.awt.event.*;
       import java.awt.Color;
    
        public class themeChange extends JFrame
          {
          JButton button;
          Color[] themes = {Color.black,
                            Color.blue, 
                            Color.cyan,
                            Color.darkGray, 
                            Color.gray, 
                            Color.green, 
                            Color.lightGray, 
                            Color.magenta, 
                            Color.orange, 
                            Color.pink, 
                            Color.red, 
                            Color.white, 
                            Color.yellow};
           public themeChange()
             {
             
             button = new JButton("Change Theme");
             button.addActionListener(
                                   new ActionListener(){
                                     int i = 0;
                                      public void actionPerformed(ActionEvent e){
                                        button.setBackground(themes[i]);
                                        i++;
                                        i=i%13;
                                        }
                                     });
             
             add(button);
             }
             
           public static void main(String args[])
             {
             themeChange frame = new themeChange();
             frame.setSize(500, 500);
             frame.setVisible(true);
             }
          }
    Maybe it is because theme3() is static

  5. #5
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    yeah!

    some of the little things in programming are so frustrating...

    sometimes I end up finding the answer by sheer luck...
    I had to make it an inner class though, so the code seems too long to me =/ But I guess that's inevitable since they're so.."related" =/

    What about setting Look and Feel, does that have some sort of system stuff that makes it complicated? For example multiple look and feel's at the same time aren't supported. etc...

Similar Threads

  1. problem with argument list and precedence "(" and ")"
    By helpisontheway in forum Advanced Java
    Replies: 6
    Last Post: 12-24-2009, 07:50 AM
  2. Replies: 2
    Last Post: 10-08-2009, 11:28 PM
  3. how to make joptionpane "always on top"
    By kapilverma32 in forum Advanced Java
    Replies: 2
    Last Post: 02-06-2009, 07:57 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •