Help Regarding Background color(Java)

Discussion in 'Mac Programming' started by Alvinkiang, Apr 24, 2006.

  1. macrumors newbie

    Joined:
    Apr 24, 2006
    #1
    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
     
  2. macrumors 6502a

    Joined:
    Jun 17, 2003
    #2
    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
     
  3. thread starter macrumors newbie

    Joined:
    Apr 24, 2006
    #3
    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...
     
  4. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #4
    Code:
    #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
     

Share This Page