How to edit an item in a JComboBox

I want the user to be able to edit an item in a combobox box. You select an item, edit in the top, press enter, and viola, the item is renamed.
I've tried some approaches but they're not working out. Thanks for any ideas. What's the point of having an editable combobox if it doesn't EDIT?!

Hi,
should be as easy as:
String[] patternExamples = {
      "dd MMMMM yyyy",
      "dd.MM.yy",
      "MM/dd/yy",
      "yyyy.MM.dd G 'at' hh:mm:ss z",
      "EEE, MMM d, ''yy",
      "h:mm a",
      "H:mm:ss:SSS",
      "K:mm a,z",
      "yyyy.MMMMM.dd GGG hh:mm aaa"
JComboBox patternList = new JComboBox(patternExamples);
patternList.setEditable(true);
patternList.addActionListener(...);

Similar Messages

  • 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;
    }

  • How to Edit work item in Workflow

    Hi all,
    I have a requirement like this .....
    I have to process the Error Idoc  to the respective Sap Business workplace based on the Position assgigned.
    Now my question is...I am able to send the IDOC to the Business workplace as work item. But the USER wants to Edit the Idoc and process it further...Please guide me how to approch it.
    Thanks in advance
    Chakri

    Hi,
    I am after processing the Idoc to Work item...
    Double click on the work item which in turn takes to the "Display Record"...in the screen itself..Menu bar
    we have EDIT --> Foreground Processing   ---> Visible
                                 Foreground from Error    ---> Visible
                                 Background Processing  ---> Visible
                                 Set delete Indicator          ---> Visible
                                 End process                                    ---> Disable
                                 Continue Despite syntax error        ---> Disable(Want this to show in Visible )   
    Please help me on this case.
    Thanks in advance
    Chakri

  • How to edit/delete items in a shuttle?

    Hi,
    I have three items on the page.
    :p1_Project(lov),:p1_Product(lov),:p1_Application(shuttle item).
    A user wil first select his project and then select a product.Based on the product the shuttle populates the list of values.For eg...(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) for product A.
    Later the user might edit /delete the shuttle items.Can the shuttle be populated with the values that were selected by the user?
    For eg, For Project, user chooses product A and chooses A1,A4,A5,A6 from the shuttle item.
    scenario 1:
    Later, user wants to add A3,A8,A9 the the existing list (A1,A4,A5,A6).How to ensure that the shuttle does not show the existing list (A1,A4,A5,A6) but shows the rest of the values.
    scenario 2:
    User wants to delete A6 from his list for product A.How to make the shuttle show the default values that the user has selected already,so that user can delete A6 from the list?
    I am using Apex 3.1
    Can anyone guide me on this?
    Thanks in advance,
    Anandi
    Edited by: user9201746 on Mar 1, 2011 2:41 AM

    A little research revealed addons can add items to context menu, in this case multifox adds option to open tab in new profile for multiple gmail etc logins. I had updated addons earlier, think that triggered it. So now I know why and what it does. The problem is why 6 times listed (instead of just one)... it also varies, sometimes the context menu will have one instance... and have seen as many as 9. Not sure why it varies, but would still also like to know how to modify context menu. Could just be a bug in multifox with FF17 I suppose. I will disable multifox and see if problem goes away.

  • How to insert new Item in JCombox through setEditable?

    Hey guys,
    Is there somebody who can help me on how to insert new Item in the JComboBox through setEditable?
    JComboBox box  = new JComboBox();
    box.addItem("");box.addItem("a");
    box.addItem("b");
    box.setEditable(true);
    When I run it and selected the index 0 which the one which color red, I want to edit it and when I press enter key it will add a new item, but preserving this " box.addItem(""); , what I want is to add like this one, box.addItem("The new text entered"); "
    Can you help me with this one... Thanks

    hello,
    the following demo may help,
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultComboBoxModel;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    * comobo.java
    * Version 1.0
    * Date Jan 3, 2006
    * Copyright spatika
    public class comobo extends JFrame implements ActionListener{
         JComboBox jc = new JComboBox();
         DefaultComboBoxModel lm = new DefaultComboBoxModel();
         JButton jb = new JButton("add");
         public comobo(){
              lm.addElement("");
              lm.addElement("1");
              lm.addElement("2");
              lm.addElement("3");
              jc.setModel(lm);
              jc.setEditable(true);
              jb.addActionListener(this);
              getContentPane().add(jb,BorderLayout.NORTH);
              getContentPane().add(jc,BorderLayout.SOUTH);
              pack();
              setVisible(true);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public void actionPerformed(ActionEvent i){
              Object text = jc.getSelectedItem();
              jc.setSelectedItem(null);
              lm.addElement(text);
         public static void main(String artgs[]){
              new comobo();
    }thanks
    daya

  • How to edit the list box items in labwindow/​CVI?

     how to edit the list box items in labwindow/CVI?

    Listbox items cannot be edited directly in the control: what you can do is to select a line an, transfer its content to a textbox control, edit text there and move text back to the listbox control. Available interactions with the listbox control are listed in the help.
    An alternative to it is to use a tree customized to appear like a listbox: tree item labels can be edited directly in the control, at least those in the base column of the tree. You can look at the example \samples\userint\treelist.cws that shows how a tree can be customized this way. I haven't opened it, but this old example too should show the ability to edit tree cells.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How to select multiple items in JComboBox

    Is it possible to select multiple items in a JComboBox
    if yes, then how to do?
    If no , then is there any other way to acheieve this ?

    Hi
    ComboBoxModel extends ListModel and not ListSelectionModel, so i think JComboBox does not provide multiple selection. But u can try customizing ur combo box.. may be its possible.. not very sure
    Shailesh

  • How do I edit an item in my reading list in Safari version 7.0.2?

    How do I edit an item in my reading list in Safari version 7.0.2?
    MacBook Pro Late 2008, Running Mavericks OS 10.9.2.
    Safari version 7.0.2.

    Right or control the web address then click then click:
    Open in new tab / Open in new window / Mark as unread / Remove Item / or Clear Items.

  • How to edit items of a combo box that is part of an array of clusters

    Hi,
    In the attached vi, I have an array of clusters, and each cluster contain two combo boxes. How do I edit the items in Combo Box 1 for all elements of the array? (All Combo Box 1 elements shall include the same items.)
    For illustration, I also included the trivila case, i.e., editing the items in a separate combo box that is is not part of an array of clusters (Combo Box 3). Please advise. Thanks.
    Peter
    Solved!
    Go to Solution.
    Attachments:
    Question Combo Box in Array of Clusters.vi ‏16 KB

    Please mark S_Mercurio's message as the solution to your question rather than your own thank you  message.  First you will have to unmark  yours by going to the option menu to the upper right of your message.

  • How to reach Combobox Items via Key pressed (Java5)

    Hallo all,
    I have a question. I have a JCombobox field and assume that it has its items like (Apple, Banana, Pear). How can I manage to jump into Pear item by pressing P in that combobox?

    I am sorry I was wrong. I had to tell that my Combobox value is in my Table and the CellListener doesn't allow to do that. If I am gonna have another Swing problem I am going to send my message to that forum. I don't want to duplicate this question right now. Here is my code.
        public void load() {
            serviceType = data.getMetadata(position).getMetadataValuesSorted().toArray(new MetadataValue[0]);
            String[] metadataValues = new String[serviceType.length];
            for (int i = 0; i < serviceType.length; i++) {
                MetadataValue values = serviceType;
    metadataValues[i] = values.getValue();
    final TableColumn col2 = table.getColumnModel().getColumn(1);
    col2.setCellEditor(new MetadataValueComboBoxEditor(serviceType));
    col2.setCellRenderer(new MetadataValueComboBoxRenderer(serviceType));
    public class MetadataValueComboBoxRenderer extends JComboBox implements TableCellRenderer {
    public MetadataValueComboBoxRenderer(final MetadataValue[] items) {
    super(items);
    final JComboBox newItems = new JComboBox(items);
    setRenderer(new DefaultListCellRenderer() {
    public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    if (value != null && value instanceof MetadataValue) {
    value = ((MetadataValue) value).getValue();
    final String valueString = (String)value;
    newItems.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    for (int i = 0; i < items.length; i++) {
    if (e.getKeyChar() == valueString.charAt(0)) {
    newItems.setSelectedItem(newItems.getComponent(i));
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    registerComponent(this);
    public Component getTableCellRendererComponent(final JTable table, final Object value,
    final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    if (isSelected) {
    setForeground(table.getSelectionForeground());
    super.setBackground(table.getSelectionBackground());
    } else {
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    setSelectedItem(value);
    return this;
    public class MetadataValueComboBoxEditor extends DefaultCellEditor {
    public MetadataValueComboBoxEditor(final MetadataValue[] items) {
    super(new JComboBox(items));
    final JComboBox newItems = new JComboBox(items);
    registerComponent((JComponent) this.getComponent());
    ((JComboBox) getComponent()).setRenderer(new DefaultListCellRenderer() {
    public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    if (value != null && value instanceof MetadataValue) {
    value = ((MetadataValue) value).getValue();
    final String valueString = (String)value;
    newItems.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    for (int i = 0; i < items.length; i++) {
    if (e.getKeyChar() == valueString.charAt(0)) {
    newItems.setSelectedItem(newItems.getComponent(i));
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    MetadataValueComboBoxEditor  and MetadataValueComboBoxRenderer inner classes doesn't allow me to select the item via key pressed.
    Edited by: NEO1976 on Mar 24, 2008 10:11 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Urjent-how to add line items in tcode-FBL3N

    Hi Experts,
      How to add line items customer, customer name,  vendor and vendor name in FBL3N.
    Thanks in advance.
    mahe
    Moderator message - Please do not use words like "urjent". Please ask a specific question. Please search the forum. This question has been asked and answered before. Post locked
    Edited by: Rob Burbank on Apr 29, 2009 11:27 AM
    Edited by: Rob Burbank on Apr 29, 2009 11:28 AM

    Hi,
    Check the BTE's:
    00001020     POST DOCUMENT:       Prior to final checks             SAMPLE_INTERFACE_00001020
    00001025     POST DOCUMENT:       Final checks completed       SAMPLE_INTERFACE_00001025
    00001030     POST DOCUMENT:       Posting of standard data     SAMPLE_INTERFACE_00001030
    00001050     POST DOCUMENT:       Accounting interface           SAMPLE_INTERFACE_00001050
    Thanks & Regards,
    Harish

  • How can I surrend the focus of Jcombobox in Jtable?

    There are a jcombobox for each row of a jtable. I can click each cell to choose some value from the item list of jcombobox.
    The problem is, when I import data into the table by changing the values of tablemodel, if some cell still hold the focus, the table won't show the new imported data for this specific cell, but keep the old one. Others cells without focus work well.
    For example, originally I choose a "Monday" from the combobox with focus. When I import new data (by clicking some button), for instance "Tuesday", the new data doesn't show in the focused cell.
    So, how can I surrend the focus of this specific cell to other components, for instance, some button?

    In your action for your button, before you update your table with the imported information do the following:
    if (myTable.isEditing())
        myTable.getCellEditor().stopCellEditing();
    }

  • Can not edit Calendar Items on iPhone 4 that were sent from Outlook 2013

    Hi Folks,
    When receiving a calendar item from Outlook 2013, I can accept it, but not edit it. When I receive the same item from Outlook 2003, I can accept AND edit.
    How can I edit calendar items sent from Outlook 2013?
    We are not using an Exchange server, simply sending the calendar items via email. We noticed this when we upgraded our office from MS Office 2003 to 2013.
    Thank you so much for your help!
    Ben Bolduc

    Are you sure the Outlook 2013 calendar entries are set set to shared?
    The following thread seems to document and discuss the topic well:
    http://community.office365.com/en-us/forums/158/t/171357.aspx

  • How to Edit PSD Files In Flash Template

    Hi Everyone,
    I am new to flash and I am trying to create my first flash site using a template that I have downloaded. I can edit the first page fine, but when I click the "about us" or any other section, the standard template text, Which isn't even in english, appears. I believe that these are psd files, and I have tried to edit them, saved and replaced file on my computer, but still I get the same unchanged text on this site when I preview. Could someone please tell me how to edit and replace these files within the flash movie?

    Instance names are the reference names that you give to the individual items on the stage. Only movieClip and button symbols can have instance names.
    When you import a photoshop file to Flash you will get individual bitmap objects on the stage and in a folder in the movie's Library. You will need to select each item, one at a time, on the stage and convert each one to a symbol. When you make that conversion the name that you give to that new movieClip or button is the name that you will see in the Library.
    When you select that new symbol on the stage, look at the Properties window. You will now see a space at the top where you can give that item an instance name. The instance name is what you will use in Actionscript to control that object on the stage.
    When you look in the movie's Library, you will see the original bitmap and the symbol that you created that contains that bitmap.
    Does that help?

  • How to edit existing Spry Menu?

    I created a Spry Menu, but now that it's published (saved) I
    don't see how to edit it so I can easily add more menu items using
    DW's visual tool. All I can get to is the menu's CSS.
    How do I edit an existing Spry Menu to add/remove more items?
    I'm using CS3.

    I guess I dont understand. You can add or remove or change
    the menu in the
    properties panel. You can do all that in the design view as
    well, so I'm
    not sure what I am missing.
    Is the page available to view?
    "morkafur" <[email protected]> wrote in
    message
    news:goja98$mho$[email protected]..
    >I guess I'm not being clear. Sorry.
    >
    > What I'm saying is that when I click "anywhere in the
    menu" or the border
    > around it, I don't get the display where I can click the
    "+" to add a menu
    > item.
    >
    > For example, I have a menu item called "Capabilities".
    If I click that
    > menu
    > item I see properties for it, no problem. I get this.
    >
    > What I'm trying to do, however, is get back the the Spry
    menu item
    > DESIGNER
    > where I can add/remove menu items graphically.
    >
    > Regardless of where I click, that designer does not
    re-appear.
    >
    > If I click the Spry menu item on the toolbar, CS3
    creates a new menu, but
    > doesn't let me edit (using the menu designer) the
    existing one.
    >
    > -- M
    >

Maybe you are looking for