Adding string to combobox

Greetings~
I am encounter a problem in adding string to combobox. It is not a normal string. My string is like that "I have a red apple", I want the red in 'red' color and the other text in 'black' color, is it possible to deal with that problem..
Thank you
Puikay

It is possible, but it is also a lot of work. One way to do this is to provide your own renderer and parse the strings there to set the colors. I know that JLabel can interpret HTML code. If your combobox is not editable, you could use a JLabel and change the background color and border to make it resemble a JTextField. Anyway this is just an idea.

Similar Messages

  • Localization issue: adding strings to locale swfs

    We are currently building an application that hosts flex
    modules within an ASPX application. We have a "homepage" that
    allows users to configure which dialogs (we call them widgets) will
    show on their homepage. At this point, we have had one resource
    bundle (.properties file) that we have used for all of the strings.
    We compile these resource bundles in the locale swfs for each of
    the 8 langauges we support.
    The twist is that we also allow customers to write "custom
    widgets" in Flex that they can add to the homepage if they so
    desire. It sounds like they could create a custom .properties file
    which would allow us to create a seperate resource bundle for the
    strings for their dialog. But then would the en-us.swf have to be
    recreated to include their bundle in the overall swf? If so,
    wouldn't the client have to have our "standard app" .properties
    file to make one cumulative en-us.swf?
    Or can you have multiple locale swfs for different dialigs
    (ie Standard.us-en.swf and Custom.us-en.swf)? That way our standard
    strings stay seperate, but the client can still add their own?
    Anyone have any thoughts?

    I think you can have separate locale swf. I think you can use
    loadResourceModule() to load any resource swf. See FB3 help topics:
    Localizing Flex Applications
    Using resource modules
    Creating resource bundles at run time

  • Adding string methods? not concat

    How can I add together strings such as "1" + "2" = "3"
    not "1" + "2" = "12"
    if there is no way to do this, how can I convert a string value such as "1" to 1, so I can then add these integers together?
    Any help is appreciated.
    thanks, Patrick.

    class StringAdd {
         private String one = "1";
         private String two = "2";
         private String result;
         public StringAdd() {
              result = String.valueOf(Integer.parseInt(one) + Integer.parseInt(two));
              System.out.println(result);
         public static void main(String[] argv) { new StringAdd(); }
    }

  • Adding string to gui installation

    Hi,
    I have installed a gui 710 server
    i want to enter a string for the snc field at the end of the installation
    Can anyone assist me with this?
    Regards,
    Moshe

    The SNC Name contained within the system entry can be set in the saplogon.ini file.  Is that the area you're talking about?

  • Adding String to StringArray

    hi,
    I have a string array like String[] xx = {"A" , "B"};. And i want to append this string array with a string which i give it during the run time. How should i have to do.
    Thankx in advance.

    str1[0] = str2;
    str1[1] = str3;But I think you should really take a look at one of the Collections in Java (most likely you'll want a List, such as the aforementioned ArrayList), if you need functionality like dynamic size, deleting, etc:
    List listOfStrings = new ArrayList();
    listOfStrings.add("xx");
    listOfStrings.add("yy");
    listOfStrings.add("zz");
    listOfStrings.remove("yy");
    Iterator it = listOfStrings.iterator();
    System.out.println("Contents of listOfStrings:");
    while(it.hasNext()) {
    System.out.println((String)it.next());
    }

  • Adding objects in comboboxes using Forte

    How do you add any item in a combobox in Forte

    Under properties select Code\Custom Creation
    and type something like this.
    = new JComboBox( myVector);
    Make sure you populate your Vector before initComponents.
    You can also look here.
    http://swforum.sun.com/jive/forum.jspa?forumID=78

  • Error while Adding values in ComboBox

    Hi All..
    Valid Value- Value already Exists
    I'm getting this error while trying to add values in combo from database...
    Thanks...

    Hi..I have tried it but it doesn't work...
    Actually what i want is once i'm in the find mode and operate something then if immediately i changed to add mode then combo's selected index should be -1 or 0 but currently it selects the value in add mode which i have selected in Edit Mode...
    Thanks......

  • Re: Combobox Listener troubles

    Your JPanel should not be implementing ItemListener. The ItemListener is added anonymously to the ComboBox:
    jComboBox1.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    jComboBox1_itemStateChanged(e);
    Just remove the "implements ItemListener" from the cptables class declaration.

    You're using JBuilder?
    Ok, then
    1) click to the Design tab.
    2) select the combobox
    3) on the right hand side, there's a panel with all the component attributes. There's another tab (look at the bottom) for events. Click that tab
    4) Now select the event handler you'd like for the combobox (I suggest "actionPerformed")
    In the method that it creates for you:
    String item = combobox.getSelectedItem();

  • Difference in String joining

    String m="Hello"
    Is there any difference between
    m=m+" Java";
    and
    m=m.concat(" Java");There must be some difference I guess, but not sure where.
    Can anyone explain please?

    Another interview question?
    Adding strings with + gets compiled into instantiations and invocations of StringBuffer or StringBuilder, invoking append() on it, and then calling toString on it. That is, unless the stuff you're adding is all immutable at compile time, in which case the concatenation happens at compile time and the class just has a big string.
    .concat(), I presume, creates a new String object right there and doesn't get transmogrified into anything else at compile time.
    As such, if you're doing a lot of string concatenations, or if the concatenations are built with immutable values, it's more efficient to use +. On the other hand if you're doing a single concatenation using a variable, .concat() is probably more efficient.
    But these are just educated guesses. Try experimenting with both, disassembling the class files with javap to see what happened, looking at the source code, etc.

  • How to assign to String[] from StringBuffer in a loop?

    Hi all,
    public class Test {
    public String[] getSJ() 
            String[]    jg;
            String[]    jig;
            String[]    tg;
            String[]    result;
            Date startTime;
            StringBuffer buf = new StringBuffer();
            int i;
            int j;
            int k = -1;
    jg = {"g1", "g2"};
    for( i=0; i < jg.length; i++ )
             jig = {"1", "2", "3"};
             for( j=0; i < jig.length; j++, k++ )
                   buf.append( jg[i] ).append( ":" );                                      
                   buf.append( jig[j] ).append( ":" );   
                   buf.append( Date() );    
                   result[k] = buf.toString();
                   buf = null;
    }I want to add to result string array by assigning from buf which is StringBuffer in a loop. But what happens after buf = null??
    Will the added String be gone?
    Or should I just do:
    buf = "";
    and continue with the loop and the string objects will be preserved? But isn't result just an array of references?
    Many thanks,

    I am not sure I understand correctly. Here is a test program (in real program I call APIs from a library which returns String[] for jg and for jig, i.e they are changing in the loop in runtime.
    I tried to put together test program:
    import java.util.*;
    public class Test {
         public void Test() {
    public String[] getSJ()
            String[] jg = {"g1", "g2"};
            String[] jig = {"1", "2", "3"};
            String[]    result = new String[50];
            StringBuffer buf = new StringBuffer();
            int i;
            int j;
            int k = 0;
    for( i=0; i < jg.length; i++ )
             for( j=0; i < jig.length; j++, k++ )
                   buf.append( jg[i] )
                      .append( ":" )
                      .append( jig[j] )
                      .append( ":" )
                      .append( new Date() );
                   result[k] = buf.toString();
                   buf = null;
       return result;
    public static void main( String[] args ) {
        Test   t = new Test();
        String[] res = t.getSJ();
        for( int i=0; i<res.length; i++ ) {
         System.out.println( res[i] );
    }but when I run it fails in this statement:
    buf.append( jg[i] )
                      .append( ":" )
                      .append( jig[j] )
                      .append( ":" )
                      .append( new Date() );Exception in thread main
    java.lang.NullPointerException
    java.lang.String[] Test.getSJ()
    Test.java:24
    void Test.main(java.lang.String[])
    Test.java:38
    Wierd!?
    And if I change to:
    buf.setLength(0);
    then it fails with this error:
    Exception in thread main
    java.lang.ArrayIndexOutOfBoundsException: 3
            java.lang.String[] Test.getSJ()
                    Test.java:24
            void Test.main(java.lang.String[])
                    Test.java:38Also, I would like not to have to allocate like in:
    String[] result = new String[50];
    because I do not know how many different Strings in array will be returned by API. Is it possible to dynamically adjust
    String[] result
    somehow?
    Many thanks,

  • Right Justify string value in Transformation

    Hi need help
    I have a transform like this.. I need to add 4 spaces before the String "MARKED"
    <ns0:dest>
    <xsl:value-of select='concat(" ","MARKED")'/>
    </ns0:dest>
    but I always get result as
    <dest>MARKED</dest> instead of <dest> MARKED</dest>
    How do I get spaces before string..

    If you add them to the end, they disappear too ?
    can you try adding string() around the " ","MARKED" and second test around the concat().
    don't have a running soa suite installation over here so need to do some guessing

  • How can I show JTree inside the ComboBox!!!!!!!

    hi,
    Is there a way to show JTree in a JComboBox. As JComboBox have the following constructors..
    JComboBox()
    JComboBox(ComboBoxModel aModel)
    JComboBox(Object[] items)
    JComboBox(Vector items)
    Is there a way That I can put JTree in a JComboBox i.e.
    to have a constructor like this
    JComboBo(JTree jTree)
    thanks for help....

    actually I have built a custom FIleDialog. I am getting a tree structure in my JComboBox. But I am stuck at one point whenever I click on the directory that is shown in the table the name of the directory is added to the comboBox under the parent directory and is selected by default and it's contents are shown in the Table now my problem is that if I have the folder whose name is same is it's parent directory and when I click on that it's contents are shown in the Table but the it's name is not added in the comBobox instead it shows me the parent directory. Infact it should add the name in my Combobox and get this one selected not it's parent with the same name. I want it to work like file dialog. Like in FileDialog if we have a parent directory and child directory with the same name they are shown and selected properly, I am trying to do the same way but no success.So to get arround this I was thinking if I can use the JTree instead of directly adding nodes to my TableModel. Or any hints how to get arround this. I do have the custom renderer and model too. Thanks for any help.

  • Combobox dropdown functionality

    Hi,
    I have a combobox dropdown for a Column in my table. it displays "codes Description" something like this
    01 Apparel
    02 Houseware
    03 Kitchenware
    I have a query to get this data in the dropdown from a oracle table.
    Select LEVEL1_CATEGORY_CD, CATEGORY_DESC From PRODUCT_CATEGORY1
    Order By PRODUCT_CATEGORY1.CATEGORY_DESC
    I am using setboundsql() method of the Column class in Quicktable.
    http://quicktable.org/doc/quick/dbtable/Column.html
    I have also tried getting the query data in a hastable as a key/value pair and fill the combo box.
    what i need is when user selects something from the dropdown like "02 Houseware" i need only 02 to be filled into my cell. is this possible? right now its filling "02 Houseware" in the dropdown. can you explain stepwise as i am new to swing API.
    Thanks.

    I guess I am close but doing something silly. thats how I learn.
    here is my code snippet,
    final JComboBox comboBox;
             comboBox = new JComboBox( model );   // model.addElement(rs.getString(1));
             comboBox.setEditable(true);
             comboBox.setSelectedIndex(-1);
          comboBox.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
         if (comboBox.getSelectedIndex()==-1) return;
         String s= comboBox.getSelectedItem().toString().trim();
        comboBox.setSelectedItem(s.substring(0,2));
          c.setCellEditor(new DefaultCellEditor(comboBox));   //c = dBTable1.getColumn(1);My vector has elements like, "01 Apparel".
    I am able to get these in the dropdown. when i select something, its filling, 01 Apparel . after selecting if i click the cell again, then its changing to 01(as i needed). else after selecting if i lose focus and go to other cell, the value remains as 01 Apparel.
    this might be trivial for someone who knows Swing but I am gettting frustrated...have to read complete tutorial this weeknd :)
    Thanks again.

  • ComboBox Jumplist

    I have a ComboBox implemented, however I am binding several hundred elements to this.
    What is the recommended way for selecting from such a large list? Ideally I would like to be able to navigate the items via a Application list type JumpList when the ComboBox is activated.

    Did you try using
    IList in order to bind to your ComboBox?
    Reference
    Binding List<string>to ComboBox</string>
    Happy Coding!

  • Adding MovieClip to DataGrid Cell

    Hi to all..
    I have added components like ComboBox, CheckBox etc in the
    DataGrid cell..
    But Now I want to add MovieClip If not possible then Swf in
    the DataGrid cell using cellrenderer.
    Is it possible to add such things.
    If yes can you guide me how..? I have spend 3 days after
    this... Please Help me out..
    Thanks.

    quote:
    Hi...
    I'm using AS3.
    By the way I have added Movieclip on the data grid cell...
    But now the problem is how to make it editable because I have
    added two components on the same cell...
    And that cell take this both component as object and you can
    not edit that object by just making that column as editable =
    true... so if any one can suggest me the way..
    the help will be appreciated......

Maybe you are looking for