Swing - colored text in Combo Box?

Hello!
I'm playing around with swing, and i would like to display a "coloured" list in my combobox. The user can select "red","green" and so one. "Red" should be written in red, "green" in green..
Is this possible??
I can only change the color of the whole list, with "myComboBox.setForeground(Color.red)"...
Cheers

You should provide a new Renderer for your combo box. look at the javax.swing.ListCellRenderer interface

Similar Messages

  • HOWTO Get the text of "combo box" and "labe" controls with JavaAccessBridge

    HOWTO Get the text of "combo box" and "labe" controls with JavaAccessBridge.
    Please help,
    I'm trying to use the Java Access Bridge (JAB) 2.1 to get the text in Java Applet controls. I've been able to use the sample code in AccessInfo.cpp sample that comes with JAB to get text from "text" controls in a Java Applet. To clarify, I am referring to the "role" in the AccessibleContextInfo struct being set to "text" or "combo box" or "label".
    The problem is, when I use the AccessInfo.cpp sample to get text from a "combo box", the accessibleText data member comes back as FALSE, and thus any of the JAB text functions like GetAccessibleTextInfo fail to get any text information from "combo box" or "label" controls.
    I've also tried GetCurrentAccessibleValueFromContext on the "combo box" and "label" controls, but the text returned is empty.
    Can anyone help?

    I have new information in regards to this issue. A contact from Sun did get to me in email and relayed that that "label" objects store their text in the "name" data member of the AccessibleContext structure. This was a big help.
    But I'm still stuck trying to get information from "combo box" and other controls, like "push button". The contact said, the Java Access Bridge does not provide all the information because it is already implemented by other interfaces like AccessibleComponent, AccessibleAction, or AccessibleSelection. The contact did not allude to whether these opther interfaces can be used along side the Java Access Bridge or not. So, I'm left a step closer to the goal, but still stuck without the full solution.
    Can one take the Java Access Bridge functions, like say those used in the Ferret sample, and close the gap to get text back from "combo box", "push button", and other controls by using some other API in conjunction?

  • Is this a known problem - Panel text and combo boxes not repainting completely when scrolling in IE?

    Looking for any insight as to what might be going on.  Would appreciate any info if anyone knows about this or similar problems..
    I have a panel with 18 children - text and combo boxes - that does not repaing correctly in IE when scrolling vertically.  The 18 children do not fit in the panel, so a vertical scroll bar appears.  The scroll works perfectly when i run through FireFox.  But it does not work in IE in this case.  The child controls appear as painted over parts of other controls.
    thx.

    Wow ...  wow...  Magic.  Your last suggestion of removing the wmode attribute worked.  The page looks great.  The scroll works flawlessly where before it mangled the child controls on the page making it look like a hurricane scene.
    The html was originally set with wmode as "opaque".  I tried changing it to "transparent" after your first response, but this made no difference.  What fixed the problem was removing the wmode attribute altogether.
    We've built a rather large application.  Is there anything we need to be aware of, or anything we need to look out for by removing the wmode setting?
    Thanks much.

  • How to programatically display text in combo box?

    Is there a way to programatically display text in a combo box.  I would like to display the word "Select" in the combo box each time my program starts.  As it is now, my combo box displays the last string that was selected the last time the program ran.
    Thanks in advance.
    Solved!
    Go to Solution.

    Actually, after actually reading your post...
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Combo box internationalization

    I'm trying to brainstorm ways that I can design my application so that I have the benefits of a drop down / combo box list and free form text entry while at the same time being as globalization ready as possible.
    I like the feature in some combo boxs where the end user may select a choice from a list but may also type in entry values that doesn't exist in the predefined list. On the other hand, I would like the predefined list to be properly localized for different target audiences - for example, if the combo contains a list of cities, I'd want the same entry to refer to the city Venice in English as Venice but as Venezia in Italian and Venise in French.
    One way of approaching this problem is two have two fields: a combo box that prohibits users from free form entry (but has a list of most choices) and a second text field that a user types in if they can't find the desired value in the combo box. The combo box entries would be stored in an locale-independent or consistent way in the data store while the display would change depending on the user's selected locale. (Unfortunately, the contents of the text box would not be in any way localized).
    Can anyone think of other ways to accomodate the goal of having a list of some sort (not necessarily a combo box) that allows user entry while at the same time most entries are stored in a locale independent way (so that they can be easily localized)?

    That's true - I didn't specify what type of combo box it is. That was intentional, as I'm open to anything that will get the job done. I have to admit to not knowing a lot about the JComboBox control but I've read the Java Swing Component Tutorial on Combo Boxes (and specifically the JComboBox) and I can see what you're talking about. It's a good suggestion that you've made.
    Part of what I need to do (and not stated in my original goal) is to be able to save the combo box's (or whatever control -- I'll call it combo box for simplicity ) value to a database (solution must work in both Oracle and SQL Server) field and then later retrieve these values to display them in a form and in a list. Issues that I'll need to deal with are sorting based on the combo field value, comparing records for equality (and specifically their combo box field values), and searching for a record based on a value in a combo box field.
    A bit more information on my requirements may help people with their suggestions - as noted, localization is a priority, data must be saved to an Oracle or SQL Server database and I need to deal with sorting, comparison, and searching based on the combo field. I will be working with a three tier architecture and a rich client tier, but would like to do as much as possible in terms of sorting, comparison, and searching at the database level for performance reasons. I'll likely need to do some work in the middle tier - what kind of support does Java give for comparing, sorting, and searching a bulk set of records, w.r.t respect to the combo box problem as I've described it so far?

  • How do I correctly use Macro Builder to have a form auto select a TAB depending on a value selected in a combo box?

    I am working in access 2013 to update a database first created in Access 2003. It has been saved as an accdb but I have the same problem in earlier versions.
    I have a Tab Control subform in my MainDataEntry form which has 5 different tabs. Each Tab has its own set of text boxes and combo boxes for data entry. At the top of the MainDataEntry form there is a Text box [Text393], which has a drop down with
    the 5 TAB names, [Mobile Device],[Computer],[Loose Media],[Network] and [Original Device]. When I select one of these values in the Text box, I would like to automatically set focus on the first Textbox or ComboBox inside the corresponding TAB.
    I have tried to do this using the MacroBuilder inside the "After Update" Property for the Text or Combo box that is on the MainDataEntry Form using "If" and "Else If" statements for the "GoToControl" action, however
    I seem to be able to only get one Tab to work. I have tried several different variations of this, putting the If statement first and the action argument second...putting all arguments inside a group, or not grouped....nothing seems to work. What am I
    doing wrong?
    EXAMPLE:
    If [Text393]=[Mobile Device] Then
        GoToControl
             Control Name   Combo471
    Else If [Text393]=[Computer] Then
        GoToControl
    Control Name   Bios_Date
    Else If [Text393]=[Loose Media] Then
        GoToControl
             Control Name   Combo659
    Else If [Text393]=[Network] Then
        GoToControl
             Control Name   User Name
    Else If [Text393]=[Original Device] Then
        GoToControl
             Control Name   Combo814
    End If

    In the Macro Builder's AfterUpdate event for [Text393]:
    GoTo Control
      Control Name =Forms!MainDataEntry.Controls(Text393.Value).Name
    To ensure that the first control on each tab receives the focus, set that control's Tab Index property to zero (0).

  • Padding on combo box

    I am trying to increase the top and bottom spacing on button and combo box type components using CSS, assuming that the same font and font size is used then I would like the components to all be the same height. However, I have run into a couple of difficulties.
    Firstly, I can't find a way to pad combo box and choice components. The following CSS will size the combo box correctly but push down the selected cell text.
    .combo-box .list-cell {
    -fx-padding: 6 6 6 6;
    Padding around the arrow button doesn't seem to work either. Secondly, adding a graphic node to a button or menu button increases it's size by 2 pixels. Am I missing a property somewhere?
    The current CSS can be found at: https://github.com/JFXtras/jfxtras-styles/blob/master/src/brume/brume.css
    Many Thanks
    Andy

    I am trying to set the height as part of the skin so no extra changes are needed. Some controls allow it but combo box doesn't seem to, wondering if the other controls allow it by coincident but this isn't the intention for CSS.

  • Flash buttons and combo box's. Help

    Ok! Picture the scene. I have a combo box on the left hand
    side of the stage that holds difrent options of color's. And on the
    right side of the stage I have ten buttons showing the color's! So
    what I want to happen is! A person come's to this page and I want
    them to be able to eather select the option with the combo box drop
    down or be able to click on one of the color button's on the right
    hand side of the stage and it select that color in the combo box. I
    need this to happen because I will have lot's of option's
    (size,stlye,color,wood color ect..) for the person to look at and
    the combo box part will be way down at the bottom of the page.
    If any one can help that would be great! Or if you know of
    tutriols out there you can point me in that direction! Thank you
    all for reading!

    In which trigger you try to do this? Have you tried with when_new_block_instance?
    Here it works!
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Tamer ([email protected]):
    Hello All
    I want to populate drop down list dynamically with this procedure. but when i use combo box every thing
    working fine. but i change to poplist (that what i want) at first time when populate the poplist working
    but when i try to repopulate the poplist i get this error message.
    'FRM-41337 Cannot populate the list from record group'
    i need to use poplist and repopulated it. how can i fix the problem.
    thankx
    PROCEDURE populate_lst IS
    p_input_query VARCHAR2(500):='SELECT ALL'
    | |' SMS_BOM_SECTION.SECTION_ID,'
    | |' SMS_BOM_SECTION.SECTION_ID Value'
    | |' FROM SMSDEV1.SMS_BOM_SECTION'
    | |' ORDER BY SMS_BOM_SECTION.SECTION_ID ASC';
    p_list_name VARCHAR2(50):='SMS_BOM_CENTRE.SECTION_ID';
    v_rg_id RECORDGROUP;
    v_list_id ITEM;
    v_rg_name VARCHAR2(20) := 'reg';
    v_retval NUMBER := 0;
    BEGIN
    --Find the list itself
    v_list_id := find_item(p_list_name);
    IF id_null(v_list_id)THEN
    bell;
    message('List item '| |p_list_name| |' did not exist');
    raise form_trigger_failure;
    END IF;
    --Find the record group itself
    v_rg_id := find_group(v_rg_name);
    --Delete the record group if it already exist.
    IF NOT id_null(v_rg_id)THEN
    delete_group(v_rg_id);
    END IF;
    --create the record group from query
    v_rg_id := create_group_from_query(v_rg_name,p_input_query);
    IF id_null(v_rg_id)THEN
    bell;
    message('Record group could not be created');
    raise form_trigger_failure;
    END IF;
    --Populate record group
    v_retval := populate_group(v_rg_id);
    --Populate the list if all is well
    IF v_retval = 0 THEN
    --Populate list
    populate_list(v_list_id,v_rg_id);
    --Delete record group
    delete_group(v_rg_id);
    ELSE
    --No able to populate record_group
    bell;
    message('can not populate the record group ');
    raise form_trigger_failure;
    END IF;
    END;<HR></BLOCKQUOTE>
    null

  • New to Java - Combo Box

    I have a Application using swing, I have a combo box with a collection of flex codes. The problem that I'm having is that system titles can have more than one flex codes. What I'm trying to do if a system title have more than one flex codes I like for the system title to be list twice with the flex code.
    For example:
              SYSTEM TITLE      FLEX CODE
    First Row     9MH16R12     9001
    Second Row     9MH16R12     9002
    The flex code are set up in combo box to allowed the user to change the flex code.
    Here is some of the code that I have written:
    public class FlexCellEditor extends DefaultCellEditor implements TableCellEditor
    public FlexCellEditor()
    super(new JComboBox());
    public Component getTableCellEditorComponent(JTable aTable, Object obj, boolean flag, int aRow, int aColumn)
    JComboBox vComboBox = (JComboBox) super.getComponent();
    SystemTitle vSystemTitle = aRow >= 0 ? model.getSystemTitle(aRow) : null;
    Collection<FlexCode> vSelected = vSystemTitle != null ? vSystemTitle.getFlexCodes() : null;
    DefaultComboBoxModel vComboMode = (DefaultComboBoxModel) vComboBox.getModel();
    vComboMode.removeAllElements();
    int vSelectedIndex = -1;
    if (vSystemTitle != null)
    for (FlexCode vFlexCode : vSystemTitle.getFlexCodes())
    vComboMode.addElement(vFlexCode);
    if (vFlexCode.equals(vSelected))
    vSelectedIndex = vComboMode.getSize() - 1;
    vComboBox.setSelectedIndex(vSelectedIndex);
    return vComboBox;
    }

    Just to provide a completely different approach:
    Instead of converting to an object array, then passing that into the combo box, you can take advantage of the MVC nature of swing (I'm assuming you are using a JComboBox):
    public class ArrayListComboBoxModel extends AbstractListModel{
      ArrayList myList;
      public ArrayListComboBoxModel(ArrayList l)
        myList = l;
      public Object getElementAt(int index) {
          return myList.get(index);
      public int getSize() {
          return myList.size();
    }Then create your JComboBox as follows:
    JComboBox box = new JComboBox(new ArrayListComboBoxModel(anArrayList));Nifty!
    - K

  • How to change the text color to red in a combo box?

    I'm writing a java program which have a combo box which shows all the name of the member from the database. However, I would like to change the text color of those member who have now currently on-line.
    Please help, it's URGENT. Thanks in advance.
    Clark

    hi,
    as i mentioned, you would require to use a custom renderer for this, for this
    //Class subclass the JFrame and has a JList in it
    import javax.swing.*;
    import java.awt.*;
    import java.util.Vector;
    public class ListRendererTest extends JFrame
         private JList lstMenu;
         private DefaultListModel defaultListModel;
         private JScrollPane scrollPane;
         private Vector listVector;
         public ListRendererTest()
              init();
              addComponents();
              showFrame();
         public void init()
              lstMenu = new JList();
              defaultListModel= new DefaultListModel();
              lstMenu.setModel(defaultListModel);
              scrollPane      = new JScrollPane(lstMenu);
              listVector = new Vector();
              MyListData m1 = new MyListData();
              m1.setName("Rakesh");
              m1.setOnline(false);
              listVector.addElement(m1);
              m1 = new MyListData();   //represents each User instance
              m1.setName("Makesh");
              m1.setOnline(true);
              listVector.addElement(m1);
              for (int i=0;i < listVector.size(); i++)
                   defaultListModel.addElement(((MyListData)listVector.elementAt(i)));
              lstMenu.setCellRenderer(new MyListRenderer());  //set custom renderer
         public void addComponents()
              getContentPane().add(scrollPane,BorderLayout.CENTER);
         public void showFrame()
              setTitle("List renderer test");
              setSize(300,300);
              setLocation(200,200);
              setVisible(true);
         public static void main(String args[])
              new ListRendererTest();
    }The above class is the Container which houses the JList in it, it uses two other classes, MyListData which is used to represent each user instance ( username, and information about whether he is online) and MyListRenderer (custom renderer).
    // Represents each user instance //
    public class MyListData
         private String name;
         private boolean online;
         public void setName(String name)
              this.name = name;
         public String getName()
              return name;
         public void setOnline(boolean online)
              this.online = online;
         public boolean isOnline()
              return online;
    //custom list renderer
    import javax.swing.*;
    import java.awt.*;
    public class MyListRenderer extends DefaultListCellRenderer
         private MyListData myListData;
         public Component getListCellRendererComponent(JList list, Object value, int index,  boolean isSelected, boolean cellHasFocus)
               myListData = (MyListData)value;
               setText(myListData.getName());
               setBackground(myListData.isOnline() ? Color.red: Color.white);  //check if online, if so show in different color
               setForeground(isSelected ? Color.blue : Color.black);
               return this;
    }hope that helps.
    cheerz
    ynkrish

  • I need a combo box with 4 values to choose from which will populate a text box on the form with text related to each combo box selection

    For example:
    Combo box choices:
    apple
    tomato
    squash
    Pumpkin
    The text box depending on the selection above would state the color:
    Green        (if Apple was chosen from the combo box
    Red           (if Tomato was chosen from the combo box
    Yellow       (if Squash was chosen from the combo box
    Orange      (if Pumpkin was chosen from the combo box
    I am very new at this and have spent hours looking for an answer.  Thank to anyone in advance who can help!

    Place each value as the export value of the options in the combo-box and then use this code as the text field's custom calculation script:
    event.value = this.getField("ComboBox Name").value;

  • Show text box from one combo box selection

    Total newb here and need help.  I tried searching for a javascript to copy/paste, but without any luck.  I am using Acrobat Pro 9.2.0.  If you could help me out with the javascript or with directions on how to make the following be accomplished, I would be greatly appreciative.
    I am creating a fillable PDF and currently have a combo box that is labeled "Internship Satisfied By" with the options of "TCoB PDP", "MRKTNG 4185", and "Other College".  I would like a hidden text box (where the end user can fill in to explain) to become visible only when the end user selects the "Other College" option, but stay hidden for the other selections.  The hidden text box is labeled "Internship Explained".
    Thanks in advance! Jarrod

    Use this code as the combo box's validation script:
    if (event.value == "Other College") {
    getField("Internship Explained").display = display.visible;
    } else {
    getField("Internship Explained").display = display.hidden;

  • How do I populate the choices in a Combo Box in a PDF Form from an Excel spreadsheet or text file?

    Pleasel let me know if there is a way to copy and paste choices for a Combo Box from an Excel spreadsheet or text file.  I have over 250 values I'd like to add and don't trust my typing!
    Thanks for the help!
    Ken K. - 2191

    Yes, using the field.getItemAt method: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.745.html
    E.g.:
    var aItems = [];
    var f = getField("combo1");
    for (var i = 0; i < f.numItems; i++) {
        aItems[i] = f.getItemAt(i);
    If there are export values you need to decide how to use the optional bExportValue parameter.

  • Access 2010 - How to display data from a table into a text box upon combo box selection?

    Hi
    I have a a table with 5 columns: month, year, USD, SGD, BAHT.
    I created a form with a combo box for selection of the month and year, and I would like to set adjacent text boxes to show USD, SGD, BAHT information. How can i go about doing that?
    From the Q&A here, most of them uses the function similar to this "=[Combo0].[Column](1)" to show the data in the text box, but this would require the combo box to list a whole bunch of details if i were to add in more currency values to the
    table. Is it possible to not show this information in the combo box, but still populate data in the textboxes base on a selection on only the "month" and "year" in the combo box.

    Hi,
    According to your description, my understanding is that you want to show only the month/year in the combo box, we can choose the date, and it will display the value of USD/SGD/BAHT based on the month/year.
    If it is, I recommend you try the steps:
    Create a form based on your data source table>Add the combo box>combo box wizard>Find a record on my form based on the value I selected my combo box>Add mouth and year to selected fields
    http://office.microsoft.com/en-us/access-help/create-a-list-of-choices-by-using-a-list-box-or-combo-box-HA010113052.aspx
    If I misunderstand something, please let me know. We may upload some screenshots or a sample through OneDrive.
    Regards,
    George Zhao
    TechNet Community Support

  • A text box should appear based on combo box selection in a jsp page.

    Hi,
    I have this problem. I ahve an option in the combo box"other". If other is selected then a text box shud appear . Can any one post a quick answer for me. may be a sample of how to do it will help me a lot.
    Thank You,
    Sagar.

    Hi Guys,
    Thnx all for ur replies. Let me explain u the scenario which i work in now. I have a combo box with 4 values "other " being the last of them. If i select "other" then a text box shud appear with the label. what happenes now is i have added onChange whn an option is changed . I have named that functiion refresh for which the code goes like this..
    function refresh()
    window.location.reload(true);
    whn i select an other option thn the whole page gets refreshed and the first value only appears. If i select other then the page refreshes and gets back again to the first value. These guys here use tags like <c: if> <C;choose> <c: otherwise> which am not familiar with. Do pls help me in retaining the option selected.. Thank You.

Maybe you are looking for