Combobox getSelectedItem method

Hi
I have a problem in retrieving combobox values.
I have a frame window with 3 textfield, 1 Combobox and 3 buttons. When I click "Ok" the frame must be closed, and i want to save the values stored in textfields and combobox at that moment. I have a problem with this last one. I get an NullerPointer exception when I try to use Combobox's getSelectedItem() method. This happen inside actionPerformed function, the one associated with OK button. Outside this function I can access combobox without problems.
Any idea?
I hope I explained clearly. If necessary I'll post some code...

RTFAPI:
<h3>javax.swing.JComboBox.getSelectedItem</h3>
Returns the current selected item....
<h4>Returns:</h4>
    the current selected Object
You get back what you put in. If you populated the JComboBox with String objects, you get back String objects.
If you populated the JComboBox with any other class of objects, the displayed value is that returned from the toString () method of the class, and getSelectedItem returns a reference to the object used for populating it.
db

Similar Messages

  • Problem with combobox.select method in 2007A

    Hi,
    When I'm trying to select the empty validvalue with a combo in SBO 2007 A, I've the error "Out of Range"
    myCombo.Select( 0, BoSearchKey.psk_Index);
    However I'm sure that the item 0 of my ValidValues is blank.
    I tried to do the same thing by value or description and it's the same problem.
    Can anyone help me ?
    Thanks
    (I'm using 2005 version of SAPboui/bobsCom.dll)

    Hi Julien,
    i tried it as
    oComboBox.ValidValues.Add("1", "Combo Value 1")
            oComboBox.ValidValues.Add("", "") - as you wrote
            oComboBox.ValidValues.Add("2", "Combo Value 2")
            oComboBox.ValidValues.Add("3", "Combo Value 3")
            oComboBox.Select("", SAPbouiCOM.BoSearchKey.psk_ByValue)
            oComboBox.Select(1, SAPbouiCOM.BoSearchKey.psk_Index)
    and both select method work. Are you sure that you have added this blank value?
    Try to debug it as
            Dim q As Integer
            Dim s As String
            For q = 0 To oComboBox.ValidValues.Count - 1
                s = oComboBox.ValidValues.Item(q).Value
            Next
    maybe it helps you.
    Petr

  • ComboBox.dataProvider method problem

    when i use this method the labels of the combo are populated.
    .i want to populate the data fields of the combo in runtime, is
    there a method or any other way to do it?

    :

  • Editable JCombobox - bug in 10.1.3

    Hi I have a JComboBox bound to a ADF view object
    JComboBox cbo = new JComboBox();
    cbo.setEditable(true);
    cbo.setModel((ComboBoxModel)panelBinding.bindUIControl("PortfolioView1", cbo));
    When I type in additional data in the combobox (its editable) and hit a "Search" button I was expected to get the newly entered value in the
    cbo.getSelectedItem() method
    This does not work though - I get the PortefolieViewRow object instead. When I instead use
    ((JUMultiAttrListEditor)cbo.getEditor()).getItem())
    I get null.
    Creating a non ADF bound combobox work fine - the getSelectedItem() return either my selection or the newly typed in value
    It clearly a bug - but is anyone aware of a workaround?
    :-) johnny

    Hi Frank
    I'm using editable comboboxes to lookup values based on a VO list. I'm aware that the entered values are not inserted in the list - this is expected.
    So I create a VO, drag it as a combobox to a Swing panel. The combobox is made editable so that I can type in info in the combobox.
    I then have a JButton that, when pressed get the value of the combobox and performs a search in the database. I use the combobox.getSelectedItem() method to get its value - this step does not work though.
    The values in the combobox is either a value the user has written (because the field is editable) or a value from the VO.
    The Combobox is not directly bound the the search button only as a lookup facility so that the user either can type in some text or select it from a list
    hope this clarified my context
    :-) johnny

  • KeyListener on combobox calander not working?

    Am trying to add keylistener on this combobox calander, but somehow its not working right. The calendar is added to a JTable and the keyListener on it works, when i gets focus, but when the popup is visible it looses the keylistener? Can someone help me with this?
    import com.sun.java.swing.plaf.motif.*;
    import com.sun.java.swing.plaf.windows.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.basic.*;
    import javax.swing.plaf.metal.*;
    import javax.swing.table.*;
    public class DateComboBox extends JComboBox
        public DateComboBox()
        public DateComboBox(int raekke,DefaultTableModel model,JTable tabel)
            this.raekke=raekke;
            this.model=model;
            this.tabel=tabel;
        public void setDateFormat(SimpleDateFormat dateFormat)
            this.dateFormat = dateFormat;
        public void setSelectedItem(Object item)
            // Could put extra logic here or in renderer when item is instanceof Date, Calendar, or String
            // Dont keep a list ... just the currently selected item
            removeAllItems(); // hides the popup if visible
            addItem(item);
            super.setSelectedItem(item);
        public void setText(String texte)
            setSelectedItem(texte);
        public String getText()
            return (String)this.getSelectedItem();
        public void setRaekke(int raekke)
            this.raekke=raekke;
        public void updateUI()
            ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this);
            if (cui instanceof MetalComboBoxUI)
                cui = new MetalDateComboBoxUI();
            } else if (cui instanceof MotifComboBoxUI)
                cui = new MotifDateComboBoxUI();
            } else if (cui instanceof WindowsComboBoxUI)
                cui = new WindowsDateComboBoxUI();
            setUI(cui);
        // Inner classes are used purely to keep DateComboBox component in one file
        // UI Inner classes -- one for each supported Look and Feel
        class MetalDateComboBoxUI extends MetalComboBoxUI
            protected ComboPopup createPopup()
                return new DatePopup( comboBox );
        class WindowsDateComboBoxUI extends WindowsComboBoxUI
            protected ComboPopup createPopup()
                return new DatePopup( comboBox );
        class MotifDateComboBoxUI extends MotifComboBoxUI
            protected ComboPopup createPopup()
                return new DatePopup( comboBox );
        // DatePopup inner class
        class DatePopup implements
        ComboPopup,
        MouseMotionListener,
        MouseListener,
        KeyListener,
        PopupMenuListener
            public DatePopup(JComboBox comboBox)
                this.comboBox = comboBox;
                setFocusable(true);
                addKeyListener(this);
                calendar = Calendar.getInstance();
                // check Look and Feel
                background = UIManager.getColor("ComboBox.background");
                foreground = UIManager.getColor("ComboBox.foreground");
                selectedBackground = UIManager.getColor("ComboBox.selectionBackground");
                selectedForeground = UIManager.getColor("ComboBox.selectionForeground");
                initializePopup();
            //========================================
            // begin ComboPopup method implementations
            public void show()
                try
                    // if setSelectedItem() was called with a valid date, adjust the calendar
                    calendar.setTime( dateFormat.parse( comboBox.getSelectedItem().toString() ) );
                } catch (Exception e)
                {e.printStackTrace();}
                updatePopup();
                popup.show(comboBox, 0, comboBox.getHeight());
            public void hide()
                popup.setVisible(false);
            protected JList list = new JList();
            public JList getList()
                return list;
            public MouseListener getMouseListener()
                return this;
            public MouseMotionListener getMouseMotionListener()
                return this;
            public KeyListener getKeyListener()
                return null;
            public boolean isVisible()
                return popup.isVisible();
            public void uninstallingUI()
                popup.removePopupMenuListener(this);
            // end ComboPopup method implementations
            //======================================
            //===================================================================
            // begin Event Listeners
            // MouseListener
            public void mousePressed( MouseEvent e )
            // something else registered for MousePressed
            public void mouseClicked(MouseEvent e)
            public void mouseReleased( MouseEvent e )
                if (!SwingUtilities.isLeftMouseButton(e))
                    return;
                if (!comboBox.isEnabled())
                    return;
                if (comboBox.isEditable())
                    comboBox.getEditor().getEditorComponent().requestFocus();
                else
                    comboBox.requestFocus();
                togglePopup();
            protected boolean mouseInside = false;
            public void mouseEntered(MouseEvent e)
                mouseInside = true;
            public void mouseExited(MouseEvent e)
                mouseInside = false;
            // MouseMotionListener
            public void mouseDragged(MouseEvent e)
            public void mouseMoved(MouseEvent e)
            public void keyPressed(KeyEvent e)
                if(e.getSource()==this)
                    if(e.getKeyCode()==KeyEvent.VK_CONTROL)
                        System.out.println("keytyped1");
            public void keyTyped(KeyEvent e)
            public void keyReleased( KeyEvent e )
                if(e.getKeyCode()==KeyEvent.VK_CONTROL)
                    System.out.println("keytyped2");
                if ( e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER )
                    togglePopup();
             * Variables hideNext and mouseInside are used to
             * hide the popupMenu by clicking the mouse in the JComboBox
            public void popupMenuCanceled(PopupMenuEvent e)
            protected boolean hideNext = false;
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e)
                hideNext = mouseInside;
            public void popupMenuWillBecomeVisible(PopupMenuEvent e)
            // end Event Listeners
            //=================================================================
            //===================================================================
            // begin Utility methods
            protected void togglePopup()
                if( isVisible() || hideNext)
                    hide();
                else
                    show();
                hideNext = false;
            // end Utility methods
            //=================================================================
            // Note *** did not use JButton because Popup closes when pressed
            protected JLabel createUpdateButton(final int field, final int amount)
                final JLabel label = new JLabel();
                final Border selectedBorder = new EtchedBorder();
                final Border unselectedBorder = new EmptyBorder(selectedBorder.getBorderInsets(new JLabel()));
                label.setBorder(unselectedBorder);
                label.setForeground(foreground);
                label.addMouseListener(new MouseAdapter()
                    public void mouseReleased(MouseEvent e)
                        calendar.add(field, amount);
                        updatePopup();
                    public void mouseEntered(MouseEvent e)
                        label.setBorder(selectedBorder);
                    public void mouseExited(MouseEvent e)
                        label.setBorder(unselectedBorder);
                return label;
            protected void initializePopup()
                JPanel header = new JPanel();
                header.setLayout(new BoxLayout(header, BoxLayout.X_AXIS));
                header.setBackground(background);
                header.setOpaque(true);
                JLabel label;
                label = createUpdateButton(Calendar.YEAR, -1);
                label.setText("<<");
                label.setToolTipText("Sidste �r");
                header.add(Box.createHorizontalStrut(12));
                header.add(label);
                header.add(Box.createHorizontalStrut(12));
                label = createUpdateButton(Calendar.MONTH, -1);
                label.setText("< ");
                label.setToolTipText("Sidste m�ned");
                header.add(label);
                monthLabel = new JLabel("", JLabel.CENTER);
                monthLabel.setForeground(foreground);
                header.add(Box.createHorizontalGlue());
                header.add(monthLabel);
                header.add(Box.createHorizontalGlue());
                label = createUpdateButton(Calendar.MONTH, 1);
                label.setText(" >");
                label.setToolTipText("N�ste m�ned");
                header.add(label);
                label = createUpdateButton(Calendar.YEAR, 1);
                label.setText(">>");
                label.setToolTipText("N�ste �r");
                header.add(Box.createHorizontalStrut(12));
                header.add(label);
                header.add(Box.createHorizontalStrut(12));
                popup = new JPopupMenu();
                popup.setBorder(BorderFactory.createLineBorder(Color.black));
                popup.setLayout(new BorderLayout());
                popup.setBackground(background);
                popup.addPopupMenuListener(this);
                popup.add(BorderLayout.NORTH, header);
                popup.getAccessibleContext().setAccessibleParent(comboBox);
            // update the Popup when either the month or the year of the calendar has been changed
            protected void updatePopup()
                monthLabel.setText( monthFormat.format(calendar.getTime()) );
                if (days != null)
                    popup.remove(days);
                days = new JPanel(new GridLayout(0, 7));
                days.setBackground(background);
                days.setOpaque(true);
                Calendar setupCalendar = (Calendar) calendar.clone();
                setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.getFirstDayOfWeek());
                for (int i = 0; i < 7; i++)
                    int dayInt = setupCalendar.get(Calendar.DAY_OF_WEEK);
                    JLabel label = new JLabel();
                    label.setHorizontalAlignment(JLabel.CENTER);
                    label.setForeground(foreground);
                    if (dayInt == Calendar.SUNDAY)
                        label.setText("s�n");
                    else if (dayInt == Calendar.MONDAY)
                        label.setText("man");
                    else if (dayInt == Calendar.TUESDAY)
                        label.setText("tir");
                    else if (dayInt == Calendar.WEDNESDAY)
                        label.setText("ons");
                    else if (dayInt == Calendar.THURSDAY)
                        label.setText("tor");
                    else if (dayInt == Calendar.FRIDAY)
                        label.setText("fre");
                    else if (dayInt == Calendar.SATURDAY)
                        label.setText("l�r");
                    //                days.add(label);
                    setupCalendar.roll(Calendar.DAY_OF_WEEK, true);
                setupCalendar = (Calendar) calendar.clone();
                setupCalendar.set(Calendar.DAY_OF_MONTH, 1);
                int first = setupCalendar.get(Calendar.DAY_OF_WEEK);
                for (int i = 0; i < (first-2) ; i++)
                    days.add(new JLabel(""));
                for (int i = 1; i <= setupCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++)
                    final int day = i;
                    final JLabel label = new JLabel(String.valueOf(day));
                    label.setHorizontalAlignment(JLabel.CENTER);
                    label.setForeground(foreground);
                    label.addMouseListener(new MouseAdapter()
                        public void mouseReleased(MouseEvent e)
                            label.setOpaque(false);
                            label.setBackground(background);
                            label.setForeground(foreground);
                            calendar.set(Calendar.DAY_OF_MONTH, day);
                            hide();
                            comboBox.requestFocus();
                            if (tabel.isEditing())
                                tabel.getCellEditor(tabel.getEditingRow(),
                                tabel.getEditingColumn()).stopCellEditing();
                            model.setValueAt(dateFormat.format(calendar.getTime()),raekke,1);
                            tabel.requestFocus();
                        public void mouseEntered(MouseEvent e)
                            label.setOpaque(true);
                            label.setBackground(selectedBackground);
                            label.setForeground(selectedForeground);
                        public void mouseExited(MouseEvent e)
                            label.setOpaque(false);
                            label.setBackground(background);
                            label.setForeground(foreground);
                    days.add(label);
                popup.add(BorderLayout.CENTER, days);
                popup.pack();
            private JComboBox comboBox;
            private Calendar calendar;
            private JPopupMenu popup;
            private JLabel monthLabel;
            private JPanel days = null;
            private SimpleDateFormat monthFormat = new SimpleDateFormat("MMM yyyy");
            //        private int antaldage=1;
            private Color selectedBackground;
            private Color selectedForeground;
            private Color background;
            private Color foreground;
        private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        private int raekke=-1;
        private DefaultTableModel model;
        private JTable tabel;
    }

    come on help plz....

  • 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 Problem to change the size of selected text in JTextPane.

    hi 2 all!
    I have a problem in combo box actions, when i change the item in the combo its set is not set at that time but that action is performed when next action is taken, i have used combobox.setAction(new StyledEditorKit.FontSizeAction(" click", 12);) command to set the size of the selected text
    Plz suggest the solution also if possible,plz provide some code for this
    Action action1 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 12);
                                       Action action2 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 14);
                                       Action action3 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 18);
    s2 = (String) cb7.getSelectedItem();
                                       if (s2.equals("Small")) {
                                            cb7.setAction(action1);
                                            e1.setSource(cb7);
                                                      } else
                                       if (s2.equals("Medium")) {
                                            cb7.setAction(action2);
                                            e1.setSource(cb7);
                                                                          } else if (s2.equals("Large")) {
                                            cb7.setAction(action3);
                                            // e1.setSource(cb7);
    when i chooze any combobox item then according to that item i set the Action on ComboBox but that action is not working properly on the selected text in the JTextPane..means selected text in JText Pane is not changes its Size according to the comboBox selected ITEM.
    PLZ plzzzzzzzzzz help me:((.i will be thankfull to u.
    thanx in advance..

    this code is not working properly according to the action i set on comboBox.Thats correct, the setAction() method is used to invoke an existing Action on the combo box, not create a new Action.
    What you need to do is have a single action that uses the information from the item that was selected to build a dynamic Action to change the font. Something like:
    public void actionPerformed(ActionEvent e)
         JComboBox comboBox = (JComboBox)e.getSource();
         int fontSize = Integer.parseInt( comboBox.getSelectedItem().toString() );
         Action fontAction = new StyledEditorKit.FontSizeAction("size", fontSize);
         fontAction.actionPerformed(null);
    }

  • 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();

  • Set combobox selection

    I have a combobox populated with a two element vector. the first item is an int, the id of the value displayed by toString
    while(rs.next()){
        vec.addElement(new Item(rs.getInt("ID"), rs.getString("AgencyName")));
    }By clicking on a table that displays previous agency transaction I would like to update the combobox i tried using cboAgencyName.setSelectedItem(pastDistRS.getInt("AgencyID"));but that sets the text of the combobox to the id. I would consider using setSelectedIndex but the combobox can be filtered so Index is not static.
    Any Ideas?

    sorry for the lack of information. I will try to be more complete in my questions from now on. I have an editable combobox populated with a vector of items, each item contains two properties. The first is the id and the second is the string.
    setSelectedItem does not work because it is trying to find 3 in the vector. 3 is not in the vector it is a property of one of the items in the vector.
    How can I use the "id" property of the item to set the currently selected value of the combo box. The "description" property is dynamically set in my implementation of your example so using setSelectedItem( new Item(3, "train") );[\code] does not work for me or I am not using it to its full potential.import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    public class ComboBoxItem extends JFrame implements ActionListener
         public ComboBoxItem()
              Vector model = new Vector();
              model.addElement( new Item(1, "car" ) );
              model.addElement( new Item(2, "plane" ) );
              model.addElement( new Item(3, "train" ) );
              model.addElement( new Item(4, "boat" ) );
              JComboBox comboBox;
              // Easiest approach is to just override toString() method
              // of the Item class
              comboBox = new JComboBox( model );
              comboBox.addActionListener( this );
    comboBox.setEditable(true);
    getContentPane().add(comboBox, BorderLayout.NORTH );
              getContentPane().add(comboBox, BorderLayout.SOUTH );
    comboBox.setSelectedItem( new Item(3, "train"));
         public void actionPerformed(ActionEvent e)
              JComboBox comboBox = (JComboBox)e.getSource();
              Item item = (Item)comboBox.getSelectedItem();
              System.out.println( item.getId() + " : " + item.getDescription() );
         class ItemRenderer extends BasicComboBoxRenderer
              public Component getListCellRendererComponent(
                   JList list, Object value, int index,
                   boolean isSelected, boolean cellHasFocus)
                   super.getListCellRendererComponent(list, value, index,
                        isSelected, cellHasFocus);
                   if (value != null)
                        Item item = (Item)value;
                        setText( item.getDescription().toUpperCase() );
                   return this;
         class Item
              private int id;
              private String description;
              public Item(int id, String description)
                   this.id = id;
                   this.description = description;
              public int getId()
                   return id;
              public String getDescription()
                   return description;
              public String toString()
                   return description;
         public static void main(String[] args)
              JFrame frame = new ComboBoxItem();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );

  • Combobox Autocomplete editor inside Jtable cell

    I have a custom combobox editor which supports the autocomplete feature as follows:
    as soon as the user keys in any character, this editor searches for the item that starts with keyed in character. This item is displayed in the editor text field and the combobox popup is set to visible and the this item is set to selected.
    this editor works fine when standalone. but the popup fails to become visible when this combobox is used as an celleditor inside jtable. infact the focus is lost from the entire table.
    can anyone suggest the possible reason (and solution if possible).
    following are the code snippets for the same: -
         private TableCellEditor addCellEditor() {
              final JComboBox myJComboBox = new PIComboBox();
              myJComboBox.setModel(new DefaultComboBoxModel(// some data model //));
              //change the size of popup window
              BasicComboPopup comboPopup = null;
              for (int i=0, n=getUI().getAccessibleChildrenCount(myJComboBox); i<n; i++) {
                  Object component = getUI().getAccessibleChild(myJComboBox, i);
                  if (component instanceof BasicComboPopup) {
                   comboPopup = (BasicComboPopup) component;
                   break;
              if(null != comboPopup)
                  comboPopup.setLayout(new GridLayout(1,1));
                  comboPopup.setPopupSize(new Dimension(200, 150));
              myJComboBox.setEditable(true);
              myJComboBox.setEditor(new ComboBoxAutoCompleteEditor(myJComboBox, 3));
              myJComboBox.setUI(new ComboBoxAutoCompleteUI());
              TableCellEditor myCellEditor = new DefaultCellEditor(myJComboBox );
              return myCellEditor;
         public class ComboBoxAutoCompleteEditor extends BasicComboBoxEditor {
         public ComboBoxAutoCompleteEditor(PIComboBox comboBox, int maxLength) {
              super();
              this.comboBox = comboBox;
              this.maxLength = maxLength;
         @Override
         public Component getEditorComponent() {
              if(null == editorComponent)
                   editorComponent = new PITextField();
                   editorComponent.setBorder(null);
                   editorComponent.setMaxLength(maxLength);
                   editorComponent.setDocument(getDocument());
              return editorComponent;
         private ComboBoxAutoCompleteDocument getDocument()
              if(null == comboBoxAutoCompleteDocument)
                   comboBoxAutoCompleteDocument = new ComboBoxAutoCompleteDocument(
                             this.comboBox.getModel());
                   comboBoxAutoCompleteDocument.addDocumentListener(new ComboBoxDocumentListener());
              return comboBoxAutoCompleteDocument;
         private class ComboBoxDocumentListener implements DocumentListener {
              public void insertUpdate(DocumentEvent e) {
                   if (updatingSelection) {
                        return;
                   SwingUtilities.invokeLater(new ScrollHandler());
              public void removeUpdate(DocumentEvent e) {
              public void changedUpdate(DocumentEvent e) {
         private class ScrollHandler implements Runnable {
              private String scrollToString;
              private int scrollToRow;
              private ScrollHandler() {
                   try {
                        int length = getDocument().getLength();
                        String text = getDocument().getText(0, length);
                        scrollToRow = -1;
                        scrollToString = (String) comboBox.getSelectedItem();
                        ComboBoxModel model = comboBox.getModel();
                        int size = model.getSize();
                        for (int i = 0;  i < size; i++) {
                             String item = model.getElementAt(i).toString();
                             if (item.startsWith(text)) {
                                  scrollToString = item;
                                  break;
                             scrollToRow++;
                   } catch (BadLocationException ble) {
                        // TODO: handle
                        ble.printStackTrace();
              public void run() {
                   final int matchCount = getDocument()
                             .getCurrentMatchCount();
                   updatingSelection = true;
                   comboBox.setSelectedItem(scrollToString);
                   if (comboBox.isDisplayable())
                        comboBox.showPopup();
                   updatingSelection = false;
                   if (scrollToRow != comboBox.getItemCount() - 1) {
                        ComboBoxAutoCompleteUI ui = (ComboBoxAutoCompleteUI) comboBox
                                  .getUI();
                        JList popupList = ui.getPopupList();
                        int rowsToAdd = Math.min(comboBox.getMaximumRowCount(), comboBox
                                  .getItemCount()
                                  - scrollToRow - 1);
                        popupList.scrollRectToVisible(popupList.getCellBounds(
                                  scrollToRow + rowsToAdd, scrollToRow + rowsToAdd));
                   if (matchCount > 0) {
                        ((PITextField)getEditorComponent()).setSelectionStart(matchCount);
                        ((PITextField)getEditorComponent()).setSelectionEnd(
                                  getDocument().getLength());
         public class ComboBoxAutoCompleteUI extends BasicComboBoxUI {
             JList getPopupList() {
                 return popup.getList();
         public class ComboBoxAutoCompleteDocument extends PlainDocument {
         public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            currentMatchCount = getLength() + str.length();
            String currentText = getText(0, getLength());
            //search the matching string here
            offs = 0;
            remove(0, getLength());
            super.insertString(offs, str, a);
         **************

    You need to create a custom CellEditor which will prevent these problems from occurring. The explanation behind the problem and source code for the new editor can be found at Thomas Bierhance's site http://www.orbital-computer.de/JComboBox/. The description of the problem and the workaround are at the bottom of the page.

  • ComboBox Matrix First Line Empty

    Hi,
    I have build a Matrix with a combo box ( ...a old story...); but when the form loads, the first line in the combo box is empty.
    I start filling the Combo Box from position 0...
    Thanks
    Rune
    oRecordset = ((SAPbobsCOM.Recordset)(oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)));
    bool vmp_Language_EN_bool = true;
    m_Language(out vmp_Language_EN_bool);
    if (vmp_Language_EN_bool)
        vDoQuery_string = "SELECT [Code],[U_English] FROM [dbo].[@FCSDK_PAY_TYPE]";
    else
        vDoQuery_string = "SELECT [Code],[Name] FROM [dbo].[@FCSDK_PAY_TYPE]";
    oRecordset.DoQuery(vDoQuery_string);
    vm_Recordset_Count_long = oRecordset.RecordCount;
    oRecordset.MoveFirst();
    SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)oForm.Items.Item("mtx_F_AA").Specific;
    SAPbouiCOM.Column oColumn = (SAPbouiCOM.Column)oMatrix.Columns.Item("mtxV_0");
    for (vRecordsetIndex_long = 0; vRecordsetIndex_long <= vm_Recordset_Count_long - 1; vRecordsetIndex_long++)
        oColumn.ValidValues.Add(System.Convert.ToString(oRecordset.Fields.Item(0).Value), System.Convert.ToString(oRecordset.Fields.Item(1).Value));
        oRecordset.MoveNext();
    oRecordset = null;
    System.GC.Collect();

    Hi Rune,
    I think that's the normal behavior, and is probably desirable.  If the first entry were automatically displayed it would become the automatic default, whether the user chose it or not.  Plus if rows get added to the source table, the one that displays first might change!   You can always do an edit to make sure it is entered before processing it.
    But if you really want a default, you can use the combobox.select method, right after loading it, to display whichever row you desire.
    for example:
    cb.Select("Visa",BoSearchKey.psk_ByDescription)
    "by description" means to select the entry where the description field is = "Visa".  You can also
    pass it the code for visa & set the searchkey to ByValue.

  • Runtime help please

    Greetings,
    First off I will admit that this a part of a project for school. I am not asking for anyone to "give me code" or to "do it for me". I am having a problem tracing a runtime error with the below code. The error only occurs when you choose a selection from the jmenu (null pointer execption on line xyz). the jmenu is supposed to update the display in the JComboBox via the setSelectedItem() and the null pointer points towards the line for the setSelectedItem(). Any assistance in pointing me towards the source of the error is appreciated.
    source code follows:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class Polygon extends JFrame implements ActionListener
    {   // start Polygon Class
         /* Variable Declarations */
         Color color = Color.red;
         JComboBox comboBox;
         boolean moving;
         boolean overload;
         /* End Variable Declarations */
         Polygon()
         { //start Polygon contructor
              addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)
                                  System.exit(0);
                   }); // ends anon class for window closing (ends program)
         /* Creation of the MenuBar */
         JMenuBar menu = new JMenuBar();
         JMenu menuColor = new JMenu("Color");
         JMenuItem makeRed = new JMenuItem("Red");
              menuColor.add(makeRed);
              makeRed.addActionListener(this);
         JMenuItem makeBlue = new JMenuItem("Blue");
              menuColor.add(makeBlue);
              makeBlue.addActionListener(this);
         JMenuItem makeGreen = new JMenuItem("Green");
              menuColor.add(makeGreen);
              makeGreen.addActionListener(this);
         JMenuItem makeYellow = new JMenuItem("Yellow");
              menuColor.add(makeYellow);
              makeYellow.addActionListener(this);
         menu.add(menuColor);
         setJMenuBar(menu);
         /* End Creation of the MenuBar */
         /* Creation of the Combo box*/
         Object [] items = {"Red", "Blue", "Green", "Yellow"};
         JComboBox comboBox = new JComboBox(items);
         getContentPane().add(comboBox, BorderLayout.SOUTH);
         comboBox.addActionListener(new ActionListener()
                   { //start anon class
                        public void actionPerformed(ActionEvent e)
                             { //start action Performed
                                  JComboBox comboBox = (JComboBox)e.getSource();
                                  String comboString = (String)comboBox.getSelectedItem();
                                       if(comboString.equals("Red"))
                                  color = Color.red;
                                       else if(comboString.equals("Green"))
                                            color = Color.green;
                                       else if(comboString.equals("Blue"))
                                            color = Color.blue;
                                       else if(comboString.equals("Yellow"))
                                            color = Color.yellow;
                             } //end actionPerformed
                        } //end anon class
                   ); //end function call for anon class
         /* End Creation of the Combobox */
         }// end Polygon contructor
         public void actionPerformed(ActionEvent e)
         {  // begins Actions
              JMenuItem menu = (JMenuItem)e.getSource();
              String menuString = menu.getText();
         if(menuString.equals("Yellow"))
         color = Color.yellow;
         comboBox.setSelectedItem("Yellow");
         else if(menuString.equals("Red"))
         color = Color.red;
         comboBox.setSelectedItem("Red");
         else if(menuString.equals("Blue"))
         color = Color.blue;
         comboBox.setSelectedItem("Blue");
         else if(menuString.equals("Green"))
         color = Color.green;
         comboBox.setSelectedItem("Green");
         } //ends Actions
    public static void main (String []args)
         JFrame frame = new Polygon();
         frame.setTitle("Project 3");
         frame.setSize(300, 300);
         frame.setVisible(true);
    } //end main
    }//end Ploygon Class

    hi
    I checked ur code.
    the problem is that u have initialized objects more than one time un necesssarly.
    my friend for selecting an item from a combo box there are some methods iside java plz refer to them.
    do not use String .equal() ...
    i am sue that u will get ue souirce code copiled if u remove those problem,s.

  • BasicComboPopup issue

    Between J2SE 1.5 and Java SE 6 the implementation of javax.swing.plaf.basic.BasicComboPopup changed in a way which breaks our application. The specific change is in the internal InvocationMouseHandler class which causes the popup to hide/unhide. In releases prior to SE 6 it didn't matter if the user clicked on an item that was already selected or not. If the user clicked an item in the popup list, the JComboBox always recieveid a setSelectedIndex() call. This, in turn, not only hid the popup but sent an ActionPerformed event. In SE 6 the BasicComboPopup mouse handler now checks to see if the user clicked on a "different" item than was perviously selected. If it is the same item, the BasicComboPopup simply closes the popup and bypasses the setSelectedIndex() call which, in turn, bypasses the action event. Since nothing "haoppens" in a class that's easy to override in the GUI application I'm a little stuck.
    For those who will ask, this manifests itself in our application when users use the keyboard to type-and-narrow to an item or arrow down to an item and then use the mouse to click the selection after the keyboard has been used. When this happens, the combo box simply closes without actually firing the action event. (Yes, they can hit ENTER from there and it works. However, users being users, they immediately noted this change in behavior and requested a "fix". No, I'm not exactly sure why if someone uses the keyboard to navigate to an item that they would want to then use the mouse to select the item they've already navigated to with the keyboard) It is a pretty narrow problem since the issue only happens if the last "keybord selected" item in the list is the one the user clicks. Nonetheless, its a change in the UI behavior that was unexcpected to us and turns out to be hard to solve.
    So...
    It would seem that I should be able to make my own version of BasicComboPopup with mouse handler behavior that I want and plug it into the UIManager or the LookAndFeel somewhere. I looked at the available keys in the LookAndFeelDefaults and didn't see anything that would do the trick.
    Can anyone point me in the right direction if I want to plug my own BasicComboPopup in somewhere?

    After taking another look I have a third and I think more appropriate work-around for the specific problem originally posted in this thread and in the java bug mentioned in this thread. It is what I was originally looking for. I basically made the JComboBox behave as it did prior to 1.6 by creating my own custom BasicComboPopup by extending it and replacing the mouse handling. As follows...
    First, I made my own custom ComboBoxUI which extends BasicComboBoxUI. This allows me to generate my custom Popup from the combo box...
    // MyBasicComboBoxUI.java
    import javax.swing.plaf.basic.BasicComboBoxUI;
    import javax.swing.plaf.basic.ComboPopup;
    public class MyBasicComboBoxUI extends BasicComboBoxUI {
        protected ComboPopup createPopup() {
            return new MyBasicComboPopup( comboBox );
    }// MyBasicComboBoxUI.java Next, I created my own ComboPopup which extends BasicComboPopup. This allows me to roll back the mouseReleased() changes made in 1.6 that changed the behavior in ways I didn't like. All of this code is basically replicated from the BasicComboPopup since the Handler class is private in BasicComboBox and could not be extended. Additionally the getHandler() method is private so I had to reimplement the createxxxMouseListerner() methods.
    // MyBasicComboPopup.java
    import javax.swing.plaf.basic.BasicComboPopup;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JComboBox;
    import javax.swing.JComponent;
    import javax.swing.SwingUtilities;
    public class MyBasicComboPopup extends BasicComboPopup {
        private MouseHandler handler;
        public MyBasicComboPopup( JComboBox combo )      {
            super(combo);
        protected MouseListener createMouseListener() {
            return getMouseHandler();
        protected MouseListener createListMouseListener()     {
            return getMouseHandler();
        private MouseHandler getMouseHandler()     {
            if (handler == null) {
                handler = new MouseHandler();
            return handler;
        private class MouseHandler implements MouseListener {
            public void mouseEntered(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
            public void mouseClicked(MouseEvent e) {}
            public void mousePressed(MouseEvent e) {
                if (e.getSource() == list)     {
                    return;
                if (!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled())
                    return;
                if ( comboBox.isEditable() ) {
                    Component comp = comboBox.getEditor().getEditorComponent();
                    if ((!(comp instanceof JComponent)) || ((JComponent)comp).isRequestFocusEnabled()) {
                        comp.requestFocus();
                } else
                if (comboBox.isRequestFocusEnabled())     {
                    comboBox.requestFocus();
                togglePopup();
            public void mouseReleased(MouseEvent e) {
                if (e.getSource() == list) {
                    if (list.getModel().getSize() > 0) {
                       comboBox.setSelectedIndex( list.getSelectedIndex() );
                    comboBox.setPopupVisible(false);
                    // workaround for cancelling an edited item (bug 4530953)
                    if (comboBox.isEditable() && comboBox.getEditor() != null) {
                        comboBox.configureEditor(comboBox.getEditor(), comboBox.getSelectedItem());
                    return;
                // JComboBox mouse listener
               Component source = (Component)e.getSource();
                Dimension size = source.getSize();
                Rectangle bounds = new Rectangle( 0, 0, size.width - 1, size.height - 1 );
                if ( !bounds.contains( e.getPoint() ) ) {
                    MouseEvent newEvent = convertMouseEvent( e );
                    Point location = newEvent.getPoint();
                    Rectangle r = new Rectangle();
                    list.computeVisibleRect( r );
         if ( r.contains( location ) ) {
                       comboBox.setSelectedIndex( list.getSelectedIndex() );
         comboBox.setPopupVisible(false);
                hasEntered = false;
                stopAutoScrolling();
    // MyBasicComboPopup.javaFinally, I set my custom UI as the JComboBox UI
    JComboBox c = new JComboBox();
    c.setUI(NewMyBasicComboBoxUI());

  • Trying to get components inside a panel in content pane

    Hello,
    I am trying to update the combo boxes inside a panel with a list of values(list is stored as an array).
    My heirarchy of components is as follows:
    frame-->contentpane-->gamepanel-->combopanel-->combobox
    i am able pass my frame into my code. now i have to get the combobox to update it.
    frame.getcontentpane()this returns to me my contentpane - RIGHT/WRONG???
    if right, after this how do i reach the combopanel and get the combobox such that I am able to write
    combobox.addItem(array)HELP PLEASEEEEEEEEEEEEE
    Thanks,
    Manju

    Be patient. 30 minutes is not a long time to wait for answers, especially on the weekend. Instead of waiting impatiently why don't you try reading sections from the Swing Tutorial. For example, How to Use Combo Boxes:
    http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
    so how do i keep the reference?Define a class variable for the combo box:
         This works on non editable combo boxes
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ComboBoxAction extends JFrame implements ActionListener
         JComboBox comboBox;
         public ComboBoxAction()
              comboBox = new JComboBox();
              comboBox.addActionListener( this );
              comboBox.addItem( "Item 1" );
              comboBox.addItem( "Item 2" );
              comboBox.addItem( "Item 3" );
              comboBox.addItem( "Item 4" );
              //  This prevents action events from being fired when the
              //  up/down arrow keys are used on the dropdown menu
              comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
              getContentPane().add( comboBox );
         public void actionPerformed(ActionEvent e)
              System.out.println( comboBox.getSelectedItem() );
              //  make sure popup is closed when 'isTableCellEditor' is used
              comboBox.hidePopup();
         public static void main(String[] args)
              final ComboBoxAction frame = new ComboBoxAction();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
    }Even though the combo box is created in the constructor, the actionPerformed() method can still access the combo box because it was defined as a class variable.

  • JTable: renderer problem-urgent

    Thanx "pasteven". That url is too good.
    I wrote my own renderer for each cell in JTable that uses JCombobox for rendering purpose. But when i select an item in that combo box, some times renderer is not setting the selected item in that combobox. Sometimes when i change the selection of item in the previous cell,it is getting reflected in all other cells of that particular column.
    Here is my code. Please help me.
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.table.TableCellEditor.*;
    import javax.swing.table.*;
    import javax.swing.DefaultCellEditor;
    public class Render extends javax.swing.JFrame {
    JTextField textField0=new JTextField();
    JComboBox cmb_Editor1=new JComboBox();
    JComboBox cmb_Editor2=new JComboBox();
    JComboBox cmb_Editor3=new JComboBox();
    EachRowRenderer rend;
    EachRowEditor eee;
    /** Creates new form Render */
    public Render() {
    initComponents ();
    rend=new EachRowRenderer();
    eee=new EachRowEditor(table);
    table.setDefaultRenderer(java.lang.Object.class,rend);
    table.setDefaultEditor(java.lang.Object.class,eee);
    cmb_Editor3.addItem("Y");
    cmb_Editor3.addItem("N");
    eee.setEditorAt(0,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(1,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(2,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(0,2,new DefaultCellEditor(new JCheckBox()));
    rend.add(0,2,new CheckBoxCellRenderer());
    rend.add(0,1,new ComboBoxCellRenderer(cmb_Editor3));
    rend.add(1,1,new ComboBoxCellRenderer(cmb_Editor3));
    rend.add(2,1,new ComboBoxCellRenderer(cmb_Editor3));
    JCheckBox chk=new JCheckBox();
    pack ();
    public class EachRowEditor implements TableCellEditor {
    protected Hashtable editors;
    protected TableCellEditor editor, defaultEditor;
    JTable table;
    public EachRowEditor(JTable table) {
    this.table = table;
    editors = new Hashtable();
    defaultEditor = new DefaultCellEditor(new JTextField());
    public void setEditorAt(int row,int column, TableCellEditor editor) {
    editors.put(""+row+column,editor);
    public Component getTableCellEditorComponent(JTable table,
    Object value, boolean isSelected, int row, int column) {
    return editor.getTableCellEditorComponent(table,
    value, isSelected, row, column);
    public Object getCellEditorValue() {
    return editor.getCellEditorValue();
    public boolean stopCellEditing() {
    return editor.stopCellEditing();
    public void cancelCellEditing() {
    editor.cancelCellEditing();
    public boolean isCellEditable(EventObject anEvent) {
    selectEditor((MouseEvent)anEvent);
    // editor.isCellEditable(anEvent);
         return true;
    public void addSeperateCellEditorListener(int row,int column,CellEditorListener l) {
    editor=(TableCellEditor)editors.get(""+row+column);
    editor.addCellEditorListener(l);
    public void addCellEditorListener(CellEditorListener l) {
    editor.addCellEditorListener(l);
    public void removeCellEditorListener(CellEditorListener l) {
    editor.removeCellEditorListener(l);
    public boolean shouldSelectCell(EventObject anEvent) {
    selectEditor((MouseEvent)anEvent);
    return editor.shouldSelectCell(anEvent);
    protected void selectEditor(MouseEvent e) {
    int row;
    int column;
    if (e == null) {
    row = table.getSelectionModel().getAnchorSelectionIndex();
    column=table.getSelectionModel().getLeadSelectionIndex();
    } else {
    row = table.rowAtPoint(e.getPoint());
    column=table.columnAtPoint(e.getPoint());
    editor = (TableCellEditor)editors.get(""+row+column);
    if (editor == null) {
    editor = defaultEditor;
    public class CheckBoxCellRenderer extends JCheckBox implements TableCellRenderer
    CheckBoxCellRenderer() {
    setHorizontalAlignment(JLabel.CENTER);
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setSelected((value != null && ((Boolean)value).booleanValue()));
    setToolTipText("checkbox");
    return this;
    public class TextFieldCellRenderer extends JTextField implements TableCellRenderer
    JTextField textField;
    TextFieldCellRenderer(JTextField textField) {
    this.textField=textField;
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setText((textField.getText() != null) ? textField.getText() : "");
    return textField;
    public class ComboBoxCellRenderer extends JComboBox implements TableCellRenderer
    JComboBox comboBox=null;
    ComboBoxCellRenderer(JComboBox comboBox) {
    this.comboBox=comboBox;
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setSelectedItem(comboBox.getSelectedItem());
    return this;
    public class EachRowRenderer implements TableCellRenderer {
    protected Hashtable renderers;
    protected TableCellRenderer renderer, defaultRenderer;
    public EachRowRenderer() {
    renderers = new Hashtable();
    defaultRenderer = new DefaultTableCellRenderer();
    public void add(int row,int column ,TableCellRenderer renderer) {
    renderers.put(""+row+column,renderer);
    public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus,
    int row, int column) {
    renderer = (TableCellRenderer)renderers.get(""+row+column);
    if (renderer == null) {
    renderer = defaultRenderer;
    return renderer.getTableCellRendererComponent(table,
    value, isSelected, hasFocus, row, column);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the FormEditor.
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    table = new javax.swing.JTable();
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    table.setModel(new javax.swing.table.DefaultTableModel (
    new Object [][] {
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null}
    new String [] {
    "Title 1", "Title 2", "Title 3", "Title 4"
    Class[] types = new Class [] {
    java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
    public Class getColumnClass (int columnIndex) {
    return types [columnIndex];
    jScrollPane1.setViewportView(table);
    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit (0);
    * @param args the command line arguments
    public static void main (String args[]) {
    new Render ().show ();
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable table;
    // End of variables declaration
    Please help me.

    I ran into the same problem in Java 1.4. The problem is that the JTable is not feeding the initial value to the cell editor. I found the following workaround. You have to override the JTable method prepareEditor() like this:
    <CODE>
    public Component prepareEditor(TableCellEditor editor, int row, int column) {
    Component ret = super.prepareEditor(editor, row, column);
    // Translate column to the data model coordinates by using the
    // identifier. We'll check only for the JComboBox columns (in
    // this example columns 8 and 9).
    int col = 0;
    String id = (String)getColumnModel().getColumn(column).getIdentifier();
    if ( id.equals( tableModel.getColumnName(8) ) )
    col = 8;
    else if ( id.equals( tableModel.getColumnName(9) ) )
    col = 9;
    if (col == 8 || col == 9) {
    String item = (String)tableModel.getValueAt(row, col);
    ((JComboBox)((DefaultCellEditor)editor).getComponent()).setSelectedItem( item );
    return ret;
    </CODE>
    You have to translate from table coordinates to table model coordinates in case the user reorders column - if you don't allow this for your table then you won't have to do this.

Maybe you are looking for

  • HT201303 I want to change my questions and answers apple account?

    I want to change my questions and answers apple account? I just can not buy anything, because when I buy it asks questions and answers from my account and I forgot

  • No sound for hello hello french app

    I purchased the app "Hello Hello French language" and the sound worked for one day.  I sent an email to their support site and received no reply. Recently, I bought an app called "Vocabulary", which teaches you vocabulary in different languages and t

  • How to edit registry in windows 7 SP1 ISO image

    How to edit registry keys in windows 7 SP1 ISO image?

  • HELP! Problem with permissions

    Here is my problem: My computer has been acting strange, sometimes it will freeze, the screen will go dark and a message will pop up saying I need to restart. This could happen anytime in the middle of the siplest task, like ejecting a disk, or in th

  • Problem with AC adapter?

    About two months ago, I took the battery out of my hp dv6 series laptop and decided to use just the AC adpater power source because I would not be toting my laptop around anywhere. I stored the battery inside a plastic container on top of my book she