PDA

View Full Version : Help Regarding Background color(Java)




Alvinkiang
Apr 24, 2006, 09:16 PM
I created a small Program to read in a XML File and to display the items on a Jpanel... All is very successful except that i am not sure how to change the Current Background Color to the Color i read From the XML file. Can Relevant Examples BY any one?:confused:
Thanks



mrichmon
Apr 24, 2006, 11:07 PM
I created a small Program to read in a XML File and to display the items on a Jpanel... All is very successful except that i am not sure how to change the Current Background Color to the Color i read From the XML file. Can Relevant Examples BY any one?:confused:
Thanks

The background color of what?

Certain parts of the Java UI on OS X using the default look and feel cannot be changed. For example, the background color on buttons cannot be altered in the default look and feel for OS X. You can change from the default look and feel to the cross-platform look and feel if you want. See the code example in the following post to find out how to manage the look and feel used

http://forums.macrumors.com/showthread.php?p=2156406#post2156406

Alvinkiang
Apr 24, 2006, 11:59 PM
The background color of what?

Certain parts of the Java UI on OS X using the default look and feel cannot be changed. For example, the background color on buttons cannot be altered in the default look and feel for OS X. You can change from the default look and feel to the cross-platform look and feel if you want. See the code example in the following post to find out how to manage the look and feel used

http://forums.macrumors.com/showthread.php?p=2156406#post2156406

actually what i meant was changing the backGround color of the Jpanel accordingly to the XML file color:

<Color>

<code>cyan</code>

</Color>

Is there any code relevant to help? i am unsure of the coding for this...

gekko513
Apr 25, 2006, 12:06 AM
#import java.util.*;
#import java.awt.*;

// in class variable declarations
HashMap colorMap;

// in a constructor or initializer
colorMap = new HashMap();
colorMap.put("cyan", new Color(0, 255, 255));
// and so forth


// in the xml parser
panel.setBackground((Color)colorMap.get(colorString));

add error checking as you see fit