How to color different elements in the JComboBox

Hi,
I have a combo box with say 10 items.I want to colour different items inside the combo box with differrent color.How to do this.?
thnx & regards
Neel

hi,
Thanks.It worked with the following Rendeerer
class MyCellRenderer extends JLabel implements ListCellRenderer {
         Vector indexVec=new Vector();
          public MyCellRenderer() {
              setOpaque(true);
          public MyCellRenderer(Vector indexVec) {
              setOpaque(true);
              this.indexVec=indexVec;
          public Component getListCellRendererComponent(JList list,
                                                        Object value,
                                                        int index,
                                                        boolean isSelected,
                                                        boolean cellHasFocus) {
              setText(value.toString());
              Color background=Color.WHITE;
              Color foreground=Color.BLACK;
             if(indexVec.contains(new Integer(index))){
                  foreground=Color.RED;
             }else{
                  foreground=Color.GREEN;
             setBackground(background);
              setForeground(foreground);
              return this;
      }but I have a problem now.previously for selection of a element or navigation from one item to the other item in the combo baox i used to get a dark blue background showing in which item I am presently now......but after adding this MyCellRenderer that is gone.
Please help in what could be the prob....how to set that color..
thnx
~Neel

Similar Messages

  • Map several records to different elements in the same xml node

    Hi,
    I am trying to map data from relational tables to elements as per my xml schema. One of my tables has several records that I need to map to different elements in the same xml node.
    For example:
    Customer_Id | Param_Id |Param_Name
    212 | 1 |State
    212 | 2 |Country
    212 | 3 |ZipCode
    I can not change the structure of this existing table and need to work with it.
    How do I map the different params for a specific customer to my Customer node in the schema?
    One option is to join on the parameters table several times, but there ought to be a better way!
    PLEASE HELP!!!
    Thanks,

    First I question the design that contains/allows 600 attributes on an element. They sound like they really should be elements in the XML.
    Regardless, the following (NOT TESTED) should work for you (assuming you want to write one SQL with 600 columns)
    CREATE OR REPLACE VIEW APPLICATION_XML
    OF XMLTYPE
    Element "LOAN_APPLICATION"
    with object ID
    substr(extractValue(object_value,'/LOAN_APPLICATION/APPLICATION_DATA/@CallID'),1,5)
    AS
    WITH parm_tb AS
    SELECT MAX(DECODE(prv_valu, 1, prv_value)) BusinessType,
           MAX(DECODE(param_id, 2, prv_value)) Product,
           MAX(DECODE(param_id, 3, prv_value)) SomethingElse
      FROM parameter_details
    WHERE prv_pmh_header_id = 1
    SELECT xmlElement
       ("APPLICATION_DATA",
         xmlAttributes
          p.prv_detail_id as "CallID",
          p.PRV_PRM_PARAM_ID as "RandomID",
          p.prv_value as AppInitDate
         xmlElement
         ("PRODUCER_DATA",
           xmlAttributes
            parm_tb.BusinessType as "BusinessType" ,
            parm_tb.Product as "Product"
      FROM parameters_table p
    WHERE p.PRV_PMH_HEADER_ID = 1

  • HT204053 i need to know how to separate different devices on the same itunes account

    I need to kow how to seperate different devices on the same itunes account

    Each of you should have their own iCloud account  which could be set up in "Settings > iCloud" (and if you asking me also for iMessage and FaceTime), but you could still use the same Apple ID for iTunes and App Store purchases which could be set up in "Settings > iTunes & App Stores" so that you only have to purchase each app or other media once.

  • How to display data elements in the tempalte header

    Hello friends
    i've this date_from and date_to parameters which are date parameters that user enters..
    based on these date parameters I want to display them in the header as
    day of date_from(for example if the date_from is 13-nov-2010.then I should display 13)and for date_to it should dispaly as 15 if for example the user enters
    16-nov-2010.(date-1's day)
    so it should break down to
    date_from-13-nov-2010, 13
    date_to- 16-nov-2010, 15
    I want these two values to be displayed in the header of the template how to do this
    pls help
    also let me know how to display data elements in the template header
    Edited by: erp on Dec 22, 2010 12:44 AM

    Hi Ananth..Thanks for ur timely reply
    Can I use it with <? substring(':date_from',1,2)?>
    where date_from is an input parameter which user enters at the run time of the report.
    I've to capture the date entered by the user and print it in the header..
    Pls reply

  • How to map Keyboard Digit tot the JComboBox?

    I want to use keyboard digit to navigate into the JComboBox instead of the arrow keys. What should I have to
    do in case. I have use Input Map and Action Map to associate keys but it wont work.

    How is this different from your earlier question?
    [http://forums.sun.com/thread.jspa?threadID=5438753]
    I'm locking this and it will be removed later. If you continue to start new threads with the same question you have already asked in an earlier thread, your user account is liable to be locked.
    db

  • How to add defferently Font to the JComboBox .

    I want add a JComboBox in my applet,and want every items of the JComboBox hava differently color and font,what i can do it.could u like to give me some example code .help!thank u!

    Hi,
    I think you can use java's powerful way of renderring html...
    here is one example that can help you....
    import javax.swing.*;
    import java.awt.*;
    public class MyCombo extends JFrame {
         public MyCombo() {
              getContentPane().setLayout(new FlowLayout());
              setSize(200,200);
              JComboBox aJComboBox = new JComboBox();
              aJComboBox.addItem("<html><font color=red>1</font></html>");
              aJComboBox.addItem("<html><font color=blue>2</font></html>");
              getContentPane().add(aJComboBox);
              setVisible(true);
         public static void main(String argv[]) {
              MyCombo aMyCombo = new MyCombo();
    Hope it will help u...
    Kind Regards
    Chetan Chandarana

  • How to sum different column in the same table

    Hi everyone
    I would like to know how can I make the sum of different column in the same table using apex
    exple:
    TR_PROJ_BIL_TRIM.ENTPIDFISC as ENTPIDFISC,
        TR_PROJ_BIL_TRIM.EXEANNEE as EXEANNEE,
        TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV as PROJBILTRIMT1PREV,
        TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV as PROJBILTRIMT2PREV,
        trunc( TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV)+(TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV)
    from TR_PROJ_BIL_TRIM TR_PROJ_BIL_TRIM
    group by TR_PROJ_BIL_TRIM.ENTPIDFISC,TR_PROJ_BIL_TRIM.EXEANNEE
    but while trying to run this script i get this error message:"ORA-00979: not a GROUP BY expression"
    thanks for reading me and I hope to hear from you soon

    Hi,
    Your question do not have anything do with APEX.
    It is pure SQL question and you will get better answer this kind questions from SQL and PL/SQL forum
    You need have GROUP BY when you use aggregate functions like SUM.
    I assume you like just add two columns.
    Try
    SELECT ENTPIDFISC
        ,EXEANNEE
        ,PROJBILTRIMT1PREV
        ,PROJBILTRIMT2PREV
        ,trunc(PROJBILTRIMT1PREV) + (PROJBILTRIMT2PREV)
    FROM TR_PROJ_BIL_TRIM
    Regards,
    Jari

  • How to import multiple elements into the same line in structure Framemaker (i.e. no carriage return between elements).

    I have a successful import process going now (DTD, EDD, ReadWriteRules, and Template) that imports a number of elements, but each onto a separate line. I now need to import three elements in a row on a single line. How do I set up to do that?

    Dear Wild,
    A container element a structured document can either be a paragraph element, that contains one or more complete FrameMaker paragraphs (elements corresponding to chapters, titles, and list items, for instance, are typically paragraph elements), or a text range element, with content that comprises part of a paragraph. An EDD doesn't need to identify paragraph elements since containers are paragraphs by default. You make an element a text range with a text format rule that specifies TextRangeFormatting.
    In your case, if you have a wrapper element that contains the three elements you want to appear on a single line, in the EDD, add a text format rule for the three inline elements that specifies TextRangeFormatting; specify the formatting of the overall paragraph in the element definition for the wrapper. If you don't have a wrapper, though, the overall paragraph will inherit formatting from whatever the containing element is; the containing element may be the document's root element or a major division such as a chapter or section. If that element's formatting is not what you want here, you can leave the "inline" elements as separate paragraph so that you can specify their formatting, but make the first two run-in heads (which is done in the Placement property of the pagination properties).
    --Lynne

  • How to make different size images the same size pdf in Acrobat.

    I am trying to place 2 different size images into acrobat to create a pdf but one image is half the size. How do i make each page the same size when the images are different sizes?

    Thank you, I changed the image size to match and then placed them in acrobat.

  • I have elements 12, running on PCS. Just bought a Mac mini, no DVD, how can I get elements onto the Mac?

    I just upgraded from a Pc to a Mac mini, how can I get elements 12 onto the Mac?

    Try this link and after installing validate with your 24 digit serial number - click here for PSE downloads

  • How to color an item in a JComboBox?

    I need to color some item of my JComboBox,.
    or color the string text or the background of the single item
    anyone can help me?

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        Object[] data = { new ColoredObject(Color.RED,"Hello"),
                          new ColoredObject(Color.BLUE,"World,"),
                          new ColoredObject(Color.CYAN,"These"),
                          new ColoredObject(Color.GREEN,"Are"),
                          new ColoredObject(Color.MAGENTA,"Some"),
                          new ColoredObject(Color.ORANGE,"Colors")
        JComboBox jcb = new JComboBox(data);
        jcb.setRenderer(new ColoredRenderer());
        content.add(jcb, BorderLayout.NORTH);
        setSize(300, 300);
        setVisible(true);
      public static void main(String[] arghs) { new Test3(); }
    class ColoredObject {
      Color color;
      Object object;
      public ColoredObject(Color color, Object object) {
        this.color=color;
        this.object=object;
      public Object getObject() { return object; }
      public Color getColor() { return color; }
      public String toString() { return object.toString(); }
    class ColoredRenderer extends DefaultListCellRenderer {
      public Component getListCellRendererComponent(JList list, Object value,
                                                    int index, boolean isSelected,
                                                    boolean hasFocus) {
        Component c = super.getListCellRendererComponent(list, value, index,
            isSelected,hasFocus);
        if (!isSelected && !hasFocus && value instanceof  ColoredObject) {
          c.setBackground(((ColoredObject)value).getColor());
        return c;
    }

  • JSF: How to determine which element has the focus?

    Hi all,
    I have a JSP with some input fields and a text area. When I press "ENTER" the data I have entered should be saved. That works fine (I use JavaScript to catch the keyPressed-event). But when I want to insert a new line in the text area, I press ENTER too and this invokes the javascript function. So it�s not possible to insert a new line in the text area. And I don`t want to save the data when I�m just inserting a new line.
    is it possible to determine which element has the focus at the moment of pressing ENTER? if it`s the text area then I won�t save the data and inserting a new line is possible? Or how to say: "Insert an new line if the user presses SHIFT+ENTER" or something like that?
    I�m using JSC for my application and this is my JS-function:
    function checkIt(evt)      
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
         if (charCode == 13)
              document.getElementById('form1:bt_Save').click();
              return false;
              return true;
    I�m looking for something like that:
    if(charCode == 13) {
    if(document.getElementById('form1:textArea').hasFocus())
    doNothing...
    else {
    document.getElementById('form1:bt_Save').click();
         return false;
    thanks for any help

    Hi,
    I searched through many forums (js of course too) but
    I couldn�t find a solution. Everybody knows how to
    set the focus but not how to get it. We often use
    JSF/JSP with javascript and maybe somebody here has
    another approach to this problem (how to solve it
    using jsf itself or anything else)?Take easy. I just suggested to search in a JavaScript forum , in your question you didn't mentioned this. Good luck man.
    Cya.

  • Dynamically remove and add element into the JCOmboBox

    Hi all ,
    I have one JComboBox .
    and I have 3 sets of values in vector form -- Vector<String> v1 , Vector<String> v2 , Vector<String> v3 .
    Depending on certain condtion I have set the values in the JComboBox .
    Can any body tell how can I achieve this
    Thanks and regards
    Anshuman Srivastava

    Replace the model.
    [http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html]

  • How to select different parts of the text? cmd button no longer does that...

    After installing Maverics i can no longer propertly edit my work as I cannot mark different parts of text using cmd button. Shift works as before for highlighting all the text from starting point to selected point but I can no longer use cmd to highlight different areas of the text. Is this an OS bug? Or was the button for selecting different parts of the text changed? I tried everything...

    It's just a small part of what makes Pages 5 so "stunning" (Apple's word). You think stripping out the nifty ability to mark non-contiguous passages of text was neat? Sure that was nice. But Apple has gotten rid of more, so much more. And for free!
    Just wait till you put the product through its paces and you discover other nice features that are missing, such as (but not limited to):
    - no linking of text boxes!  Yes, that's right. Now a newsletter that had a "continued on page 6" or whatever will be broken by Pages 5. Stunning! (Even more stunning, Pages 5 will strip out all sorts of formatting from documents created with Pages 4.3 and it will do ao without warning and will save the document in a NEW unified file format so that it cannot be opened by Pages 4.3, thereby potentially losing users hours and hours of work. Stunning!
    There's more!
    - Pages 5 has no mail merge, no bookmarks, no images in headers/footers! Pages 4.3 has those features, but this stunning new release removes them.
    - Pages 5 features vastly reduced and simplified set of templates (there used to be about 130 Apple-cupplied templates, now there are about 60).
    - Page 5 also boasts NO RTF SUPPORT, so a paper your wrote with Apple's own TextEdit is not natively readable with Pages: Stunning!
    - No detail was too small to omit in this stunning new release: the vertical ruler, so you can easily place text or an obejct at a certain place in a document: gone! Setting the default zoom: gone!  Status bar reproting word count and pagecount (e.g., Page 4 of 48): Gone! View comments in the left side bar: Gone!  Autocapitalization: Gone! Search & Replace: drastically simplified!
    But here's the really good news: Pages 5 is just PERFECT for creating a one page-poster advertising a new concert by Apple employee Eddie Cue. What's more you can collaborate on it with someone else, even if they're using a PC. Now that's "stunning"!

  • Versioned deployments: how to deploy different version of the same app ?

    I 'd like to deploy on a server (single instance) different versions of the same web application, say:
    webapp1.war
    webapp2.war
    webapp3.war
    The wars have the same ContextRoot.
    It is possible to version them with an attribute in MANIFEST.MF, but is it possible to have the N applications ACTIVE and running ? I'd like that one IP will be served from webapp1, another IP from webapp2, another IP from webapp3, etc.

    It may your 'requirement' but I have serious doubts that the app review team will approve it. Save yourself the waste of time and follow my original suggestion of one app. That's the only correct 'method' (w/IAP of course) that will have a chance of success.
    See the iOS Human Interface Guidelines and the App Review Guidelines before you go any further. In the case where you need 'official' guidance, consider using support event w/DTS

Maybe you are looking for