Results 1 to 5 of 5
- 01-04-2010, 01:29 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
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); } } }the radio button is in "MenuBar" that extends JMenuBar that is a inner class in my GUI.Java Code:final JRadioButtonMenuItem three = new JRadioButtonMenuItem("Theme: Third"); three.setSelected(true); three.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ theme3(); } });
whether I type theme3(); or GUI.theme3(); there isn't any error, the thing is, clicking the button doesn't do anything either.
- 01-04-2010, 02:01 AM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Try calling repaint() on each element after you change its background.
- 01-04-2010, 04:52 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
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
- 01-04-2010, 05:09 AM #4
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Hmm, setBackground() works for me...
Maybe it is because theme3() is staticJava 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); } }
- 01-04-2010, 01:23 PM #5
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
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
-
problem with argument list and precedence "(" and ")"
By helpisontheway in forum Advanced JavaReplies: 6Last Post: 12-24-2009, 07:50 AM -
how to override "cancel operation" in "progress bar"
By singswt in forum SWT / JFaceReplies: 2Last Post: 10-08-2009, 11:28 PM -
how to make joptionpane "always on top"
By kapilverma32 in forum Advanced JavaReplies: 2Last Post: 02-06-2009, 07:57 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks