Results 1 to 10 of 10
Thread: Original JOptionPane Color
- 10-13-2011, 11:42 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Original JOptionPane Color
hi
I changed my JOptionPane dialog boxes to colors, but i can't figure out how to change them back to the original colors. Also, if someones has a list of all the possible colors that can be used, that would very much be apreciated. thanks
Java Code:Object color = " "; Object background = " "; UIManager um = new UIManager(); color = JOptionPane.showInputDialog(null, "Choose a Color for your text", "Menu", JOptionPane.QUESTION_MESSAGE, null, new Object[] { "green" ,"red", "orange", "blue", "black", "yellow", "white" }, ""); if ( color == "green") { um.put("OptionPane.messageForeground", Color.green); } if ( color =="red" ) { um.put("OptionPane.messageForeground", Color.red); } if ( color == "blue") { um.put("OptionPane.messageForeground", Color.blue); } if ( color == "orange") { um.put("OptionPane.messageForeground", Color.orange); } if ( color == "yellow") { um.put("OptionPane.messageForeground", Color.yellow); } if ( color == "white" ) { um.put("OptionPane.messageForeground", Color.white); } if ( color == "black") { um.put("OptionPane.messageForeground", Color.black); } background = JOptionPane.showInputDialog(null, "Choose a Color for your Background", "Menu", JOptionPane.QUESTION_MESSAGE, null, new Object[] { "green" ,"red", "orange", "blue", "black", "yellow", "white" }, ""); if ( background == "green") { um.put("Panel.background", Color.green); } if ( background == "red" ) { um.put("Panel.background", Color.red); } if ( background == "blue") { um.put("Panel.background", Color.blue); } if ( background == "orange") { um.put("Panel.background", Color.orange); } if ( background == "yellow") { um.put("Panel.background", Color.yellow); } if ( background == "white" ) { um.put("Panel.background", Color.white); } if ( background == "black") { um.put("Panel.background", Color.black); }
- 10-13-2011, 11:53 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
Re: Original JOptionPane Color
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-13-2011, 11:58 AM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Re: Original JOptionPane Color
you might want to read this http://download.oracle.com/javase/tu...s/colorchooser.
And bookmark this The Really Big Index
- 10-13-2011, 12:11 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Original JOptionPane Color
@mine 0926
thanks for your links, though the first one gives me an error 404…
@Jos So basically, you want me to use if (color.equals("orange")) instead?
i'm not sure i follow- i only know basic java, if you could please elaborate, thanksb.t.w. get the color from the object before you change it so you can restore the original color afterwards.
- 10-13-2011, 12:38 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
Re: Original JOptionPane Color
Yep, the equals method compares two Strings for equality of their content. Read the following pseudo code:
1) Color originalColor= yourObject.getColor();
2) change the color of yourObject at will ...
3) restore the original color: yourObject.setColor(originalColor);
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-13-2011, 01:14 PM #6
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Original JOptionPane Color
So in my case, yourObject would be replaced by either OptionPane.messageForeground OR Panel.background??
- 10-13-2011, 01:19 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
- 10-13-2011, 01:25 PM #8
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Original JOptionPane Color
I'm still really confused as to what i need to type for the code. (for what i tried, i get an error message: cannot find symbol - method getColor() )
Last edited by jiffi; 10-13-2011 at 01:29 PM.
- 10-13-2011, 01:52 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
- 10-14-2011, 01:51 AM #10
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Re: Original JOptionPane Color
Here is the correct link: How to Use Color Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Similar Threads
-
Close a JFrame, but keep the original open.
By nolsen01 in forum AWT / SwingReplies: 3Last Post: 06-13-2011, 11:28 PM -
property values into an Enumeration object in the original order
By Zamioculcas in forum New To JavaReplies: 9Last Post: 05-12-2011, 10:51 PM -
Getting to original File location
By ravjot28 in forum New To JavaReplies: 2Last Post: 02-28-2010, 04:00 PM -
Proxy or Original...!
By Shiv in forum New To JavaReplies: 1Last Post: 04-11-2009, 03:32 AM -
Original Acro looking for Lead Java Programmer
By Doorsmaniac in forum Jobs OfferedReplies: 0Last Post: 12-20-2007, 01:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks