How to set colors???

In the code below depending on which type I call I need it to display a different color but if I specify more then one color in paint it just uses the last color specified how can I specify a color in each type outside of paint??
Here is my code:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class IconGen extends JComponent{
private Color crystalblue = new Color(128,224,255);
private Color bamboogreen = new Color(170,255,170);
private Color salmon = new Color(255,128,128);
private     Polygon p = new Polygon();
private String type;          
IconGen(String type){     //Start IconGen
          if (type.equals("Hostile")){
               int[] x = {75,125,75,25};
               int[] y = {25,75,125,75};
               int pts = 4;
               p = new Polygon(x,y,pts);
               }     //End if Hostile
          else if (type.equals("Neutral")){
               int[] x = {25,100,100,25,25};
               int[] y = {25,25,100,100,25};
               int pts = 4;
               p = new Polygon(x,y,pts);
               }     //End if Neutral
          else{
               System.out.println("ERROR: " + type + " Unknown");
}     //End IconGen
public void paintComponent(Graphics g){
               Graphics2D g2 = (Graphics2D)g;
               g2.fill(p);

Your object is considered to be null until the completion of its constructor. What would need to be done is to have a simpler constructor, and some methods outside of the constructor which are called to create your graphics. This should get around the NullPointerException. I don't do a ton of graphics programming, so I'm not sure that this is the best way, but it should work.
m

Similar Messages

  • How to set color for a tabstrip in BSP

    Hello all,
    Can anyone please let me know how to set color for a tabstripn in BSP?
    I am using the below syntax but it still gives me the default color.
    <htmlb:content design="design2003" >
      <htmlb:page title="test " >
        <htmlb:form>
    <htmlb:tabStrip id         = "TabStrip"
                          bodyHeight = "200"
                          bodyColor  = "red"
                          width      = "700" >
    </htmlb:tabStrip>
    </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    Thanks,
    Sandeep

    Hi...
    The below code is working fine for me...
    <%@page language="abap" %>
    <%@extension name="htmlb" prefix="htmlb" %>
    <htmlb:content design="design2003" >
      <htmlb:page title="stg " >
        <htmlb:form>
          <htmlb:tabStrip width      = "430"
                          bodyColor  = "rgb(88,5,64)"
                          id         = "t1"
                          bodyHeight = "112" >
            <htmlb:tabStripItem id      = "t1"
                                index   = "1"
                                title   = "Sales"
                                tooltip = "My Tooltip for Tab 1" >
              <htmlb:textView text="Tab N 1" />
              <htmlb:tree id        = "treeReports"
                          showTitle = "true"
                          table2    = "<%= mt_nodes %>"
                          title     = "Menu"
                          width     = "100%" />
            </htmlb:tabStripItem>
            <htmlb:tabStripItem id      = "t2"
                                index   = "2"
                                title   = "Production"
                                tooltip = "My Tooltip for Tab 2" >
              <htmlb:textView text="Tab N 2" />
            </htmlb:tabStripItem>
          </htmlb:tabStrip>
        </htmlb:form>
      </htmlb:page>
    </htmlb:content>

  • How to set colors in cells depending the conditions  in alvtree

    Hi All,
    Could you please provide me idea or sample program how to set colors in cells depending the conditions  in alvtree.
    Thanks,
    Suresh

    When running vim in a terminal, it will use whatever colour scheme is defined by the terminal.  You should have a look at this thread:
    http://bbs.archlinux.org/viewtopic.php?id=51818
    Also, check the wiki article on Xdefaults.

  • How to set color space to JPEG image with Java advance Imaging

    How to set color space to JPEG image with Java advance Imaging.
    is there any API in JAI which support to set color space.

    I'm definately no guru, but this is how you can change it.
    CTRL + ALT + Click on the part of the component that you want to change. This brings up the Hidden Dom Inspector, background of component will be surrounded with a red outline (Make sure the red outline is surrounding the part of the tabset you want to change), Now you go to properties sheet and click the ellipses next to rules property this will pop up a dialog you look in this list (At the top) to see the default style classes that are affecting the rendering of the component outlined in red. (You will be able to select different sections of a single component) then you just rewrite the style class that you want to change in your Stylesheet (You will not find the styleclass that you want to change because it is a part of your theme .jar but as long as you name it exactly the same and place in your stylesheet it will override the theme .jar style classes) it's actually very easy -- you were right should be a piece of cake for a guru. Don't have the link handy but you can check out Winston's Blog on changing Table Formatting to get this information...It is EXTREMELY useful if you want your apps to have a custom look and not default that comes with Creator Themes.
    Hope this helps you out God knows others have helped me alot!
    Jason

  • How to set color to a column in ALV?

    Based on standard example BCALV_GRID_01 to modify,
    how to set color to a column???
    Moderator message: please search for available information/documentation before asking.
    Edited by: Thomas Zloch on Nov 6, 2010 9:43 AM

    Hi Sai ,
    you are posting the querry in the wrong forum ..
    but still I will answer ur querry...
    Incase you are not using the standard class to make your ALV then u can set the color of each column in the propertiesof column in the design time .
    Incase u see the colors in the design time but is not able to see the colors at the run time then you check the settings of the table I dont have system right now else I could have told you exact property...
    else if u r amking alv from the standard class then u will have to search the net for the method to color the same ..
    Thanks
    Sahil.

  • How to set color profile when exporting a RAW file version as a JPEG?

    I import my raw files to Aperture and when exporting as a JPEG I want to specify a color profile of sRBG. I cannot see how to set the color profile for the export. Does anyone know how to do this?

    When you go to export versions, edit the presets, and there is a drop down box that lets you select the profile.
    I'd suggest picking up the Aperture book by Luna, Long, and Harrington. Lots of great info there.

  • [AS][INDCC] How to set Color Conversion field to No Color Conversion when creating PDF Export preset

    How can i set Color Conversion field in Export to PDF dialog to No Color Conversion when creating PDF Export preset? i have done a bit of searching and have found where it has been recommended to set effective pdf destination profile to use no profile but it doesn't seem to be producting the expected results.

    Yes, it seems that i had to make the change after creation, not while creating the preset. thank you.
    tell application "Adobe InDesign CC"
         set newPreset to make new PDF export preset with properties ¬
              {name:"preset name", standards compliance:none, acrobat compatibility:acrobat 7}
         tell newPreset to set PDF color space to unchanged color space
    end tell

  • How to set color of our specified JTable's row

    i need to set color of our specified JTable's row.so send the coddings of that part.

    i need to set color of our specified JTable's row.so
    send the coddings of that part.I think you misunderstand how this forum works...
    If you have a problem, you post your problem here with example code which demonstrates said problem...
    The people here then attempt to help you if they want to.
    You do not post demands for code examples

  • How to set colors to table control?

    Hi all,
    can we set colors to tables columns and rows?? How can we acieve this? Any help please
    Thanks,
    Madhan.

    Hi All
    thanks for your replies..
    data tab type IF_main_view=>Elements_segment.
      data line type IF_main_view=>Element_segment.
      data node_info type ref to if_wd_context_node_info.
      data attribute_info type wdr_context_attribute_info.
      data attr_value type WDR_CONTEXT_ATTR_VALUE.
      data wd_standard_cell type ref to cl_wd_table_standard_cell.
      data component like line of cl_abap_structdescr=>components.
      data wd_table_column type ref to cl_wd_table_column.
      node_info = lo_nd_segment->get_node_info( ).
      attribute_info = node_info->get_attribute( 'CELL_DESIGN' ).
    if component-name = 'SEGMENT'.
      wd_standard_cell->set_cell_design( CL_WD_ABSTR_MASTER_TABLE_COL=>E_CELL_DESIGN-BADVALUE_MEDIUM ).
    endif.
    i am trying to set color for  some colomns, but i am not getting any colors??? anything wrong in this.. please help
    thanks,
    Madhan.

  • How to set color for a particular column in advance table?

    How can we set the color of a particular column in advance table based on some parameter feteched from vo query in process request?

    i have tried the same way as mentioned in the post but ,its giving error
    java.lang.ArrayIndexOutOfBoundsException: 0
    processRequest code
    OAAdvancedTableBean table =
    (OAAdvancedTableBean)webBean.findIndexedChildRecursive("TimEntAdvtbl");
    if (table != null)
    System.out.println("table");
    OAColumnGroupBean daily =
    (OAColumnGroupBean)table.findIndexedChildRecursive("DailyColGrp");
    if (daily != null)
    System.out.println("daily col");
    OAColumnGroupBean ColGrp6 =
    (OAColumnGroupBean)table.findIndexedChildRecursive("ColGrp6");
    if (ColGrp6 != null)
    System.out.println("ColGrp6");
    OAColumnBean SatCol =
    (OAColumnBean)webBean.findIndexedChildRecursive("SatCol");
    if (SatCol != null)
    System.out.println("col");
    OAMessageTextInputBean sat1 =
    (OAMessageTextInputBean)SatCol.findIndexedChildRecursive("sat");
    if (sat1 != null)
    System.out.println("sat1");
    OADataBoundValueViewObject csssat= new OADataBoundValueViewObject(sat1,"Color");
    sat1.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, csssat);
    Error Page
    ## Detail 0 ##
    java.lang.ArrayIndexOutOfBoundsException: 0
         at oracle.sql.NUMBER._fromLnxFmt(NUMBER.java:3199)
         at oracle.sql.NUMBER.toString(NUMBER.java:761)
         at oracle.sql.NUMBER.stringValue(NUMBER.java:2090)
         at oracle.jbo.domain.Number.toString(Number.java:390)
         at oracle.apps.fnd.framework.webui.OADataBoundValue.formatObject(Unknown Source)
         at oracle.apps.fnd.framework.webui.OADataBoundValue.convertValue(Unknown Source)
         at oracle.apps.fnd.framework.webui.OADataBoundValue.convertValue(Unknown Source)
         at oracle.apps.fnd.framework.webui.OADataBoundValueViewObject.convertValue(Unknown Source)
         at oracle.apps.fnd.framework.webui.OADataBoundValue.getValue(Unknown Source)
         at oracle.apps.fnd.framework.webui.OADataBoundValueViewObject.getValue(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.getAttributeValueImpl(Unknown Source)
         at oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean.getAttributeValueImpl(Unknown Source)
         at oracle.cabo.ui.BaseUINode.getAttributeValue(Unknown Source)
    Please help

  • How to set color inputText's label

    hi,
    i have a problem with displaying labels in wrapped with PanelBox
    it's all white , unless one highlights the panel so it changed backgound color is becomes visible.
    how can i fix it or set label's color?
    <af:panelBox text="Main" id="pb1" showDisclosure="false" inlineStyle="height:566px;">
    <f:facet name="toolbar"/>
    <af:panelFormLayout id="pfl1">
    <af:inputText value="#{bindings.Id.inputValue}" label="Id" disabled="true"
    required="#{bindings.Id.hints.mandatory}" columns="#{bindings.Id.hints.displayWidth}"
    maximumLength="#{bindings.Id.hints.precision}" shortDesc="#{bindings.Id.hints.tooltip}" id="it1">
    <f:validator binding="#{bindings.Id.validator}"/>
    <af:convertNumber groupingUsed="false" pattern="#{bindings.Id.format}"/>
    </af:inputText>
    ...

    grodno wrote:
    hi,
    i have a problem with displaying labels in a form.
    it's all white , unless one highlights the panel so it changed backgound color is becomes visible.
    how can i fix it or set label's color?
    <af:panelBox text="Main" id="pb1" showDisclosure="false" inlineStyle="height:566px;">
    <f:facet name="toolbar"/>
    <af:panelFormLayout id="pfl1">
    <af:inputText value="#{bindings.Id.inputValue}" label="Id" disabled="true"
    required="#{bindings.Id.hints.mandatory}" columns="#{bindings.Id.hints.displayWidth}"
    maximumLength="#{bindings.Id.hints.precision}" shortDesc="#{bindings.Id.hints.tooltip}" id="it1">
    <f:validator binding="#{bindings.Id.validator}"/>
    <af:convertNumber groupingUsed="false" pattern="#{bindings.Id.format}"/>
    </af:inputText>
    Edited by: grodno on Dec 21, 2012 1:38 AM
    Edited by: grodno on Dec 21, 2012 1:39 AMHave you tried to set the color of the label by using css?

  • How to set color suite settings

    When I go to Bridge > Creative Color Suite Color Settings > I get " Suite color management is not enabled". I need this to be enabled?  How do I do it

    I have Illustrator and InDesign so not sure why I cant do it.
    Then that is strange indeed
    First set ID or Illustrator to the wanted color settings and then check if you can select them in Bridge. If not restart Bridge holding down option key (mac) or control key (Win) and choose reset preferences to reset prefs to factory default. This solves usually a great deal of the problems for Bridge.

  • How to set color in ui:tabSet?

    I have a web page with a ui:tabSet component.
    I need to change the background color on the area behind the tabs, but have no idea how to do it.
    I am talking about the unused space to the right of the actual tabs.
    I suspect this is something that can be set in the "style" attributes, or in a style sheet, but I do not know what the attribute is.
    Can anyone clue me in to what attribute I need to set?
    Maybe an example that I can use to set that area from the default baby blue to cyan or magenta?
    Thanks.

    I'm definately no guru, but this is how you can change it.
    CTRL + ALT + Click on the part of the component that you want to change. This brings up the Hidden Dom Inspector, background of component will be surrounded with a red outline (Make sure the red outline is surrounding the part of the tabset you want to change), Now you go to properties sheet and click the ellipses next to rules property this will pop up a dialog you look in this list (At the top) to see the default style classes that are affecting the rendering of the component outlined in red. (You will be able to select different sections of a single component) then you just rewrite the style class that you want to change in your Stylesheet (You will not find the styleclass that you want to change because it is a part of your theme .jar but as long as you name it exactly the same and place in your stylesheet it will override the theme .jar style classes) it's actually very easy -- you were right should be a piece of cake for a guru. Don't have the link handy but you can check out Winston's Blog on changing Table Formatting to get this information...It is EXTREMELY useful if you want your apps to have a custom look and not default that comes with Creator Themes.
    Hope this helps you out God knows others have helped me alot!
    Jason

  • How to set  color of a  row depending on the value of column in JTable?

    Hi All,
    I have a JTable that add rows when the user clicks on the button. In this way there can be any no. of rows in my table. My table contains five columns. When a new row is added , it is added with new data each time. Also the data of the rows keep on changing time to time.
    My problem is that when the data value for the third column comes out to be -ve then color of the row should be red and if its value is +ve then the color of the row should be green.
    I have tried for this in the way but it is not working properly.
    public Component prepareRenderer(TableCellRenderer renderer,int rowIndex, int vColIndex)
         Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
    if(rowIndex<table.getRowCount() && change<0 )
              c.setForeground(Color.red);
              c.setFont(new Font("TimesRoman",Font.PLAIN,11));
    else if(rowIndex<table.getRowCount() && change>0)
    c.setForeground(new Color(20,220,20));
         c.setFont(new Font("TimesRoman",Font.PLAIN,11));
    return c;
    where change is the value of the third column.
    Any help is highly appreciated.
    Thanx in advance.
    Regards,
    Har Krishan

    Perhaps you'll find this link useful. It gives a general idea of how you can create and adjust your custom renderer:
    http://www.senun.com/Left/Programming/Java_old/Examples_swing/JTableExamples4.html
    Hope it helps.
    Eugene

  • How to set colors on some condition in barchart

    Hi,
    I want to design a crystal report with a barchart. I should specify the color of the bar based on some conditions, this colornames are maintained in the database. I tried using chart expert -> color highlights,
    is there any other way to set the color of the bar?
    Regards,
    Deepa V

    Hi Deepa,
    In charts Color Highlight is the only way to conditionally change the color of the riser bars.
    You can use multiple conditions at a time in color highlight.
    To change the color directly you can right click the bar and select the Format Series Riser and change the color (but not conditionally)
    Regards,
    Aditya Joshi

  • [b]How to Set Color of certain text in textArea.append();?[/b]

    Hiya guys
    Could anyone give me some advise on the easiest possible way to set certain text 1 color and other text a different color when appending a string to a textarea.
    Thanks in advanced!

    You can't. Use a JTextPane:
    http://forum.java.sun.com/thread.jspa?forumID=57&messageID=1408602

Maybe you are looking for