JComboBox within JTable

Hi,
I've got the following problem with my JComboBox:
The JComboBox zcb is filled out of a database (this works!). This JComboBox is a column of the JTable jtbDauerlaeufe (this works, too!).
Now the strange behaviour:
1.) In the application I open for the first time the JDialog which the JTable is part of.
2.) Then the correct value in the JTable column is displayed.
3.) I click with the mouse in the column with my JComboBox => the ComboBox opens, but not with the selected (or displayed) value of my column, but with the first value of available JComboBox-values :-(
4.) When I leave the JComboBox and open it again, then the selected/displayed value of my column is also selected within my JComboBox.
Now my question:
Why is this behaviour not available when I open my JComboBox the first time? And what have I to do for getting the selected value of my jtable-column when I open the JComboBox the first time???
JComboBox zcb = new JComboBox();
// gets the JTable-column for the JComboBox
tc = jtbDauerlaeufe.getColumn(model.getZETColName());
// fill the values in the JComboBox
broker.getZaehlereinheitenBroker().fillComboBox(zcb);
tc.setCellEditor(new DefaultCellEditor(zcb));
Any help & hint is very welcome,
Fe

Hi
The problem is not with ur JComboBox.. It lies where u set the datavector of the JTable..
1. What type of objects does the ComboBox hold. Simple String or other Objects??
2. How do u set the JTable data the first time??
First time I think u wuld be explicitly setting the table data with different kind of objects , say string value for the column holding the combobox. Thats y the first time while loading it works properly.
Try changing the combobox values with strings instead of other Objects.. tell me if it works :)
Nisha

Similar Messages

  • Using two editor instances within JTable

    Hello,
    I'm struggling around using component editors within JTable. E.g. selectAll text on entering a JTextField cell or immediately raising the popup while entering a JComboBox cell.
    In my analysis most of these problems arises due the re-use of the cell editor.
    The event sequence is doing things in the context of the old cell while preparing the editor for the new cell has already been started.
    Because it is the same component and some things are bound deep inside the L&F it seems not easy to handle them properly.
    Just an idea from me is to avoid such problems by working with two instances for the editors in general. This should avoid all problems coming out of overlapping event processing. (To provide each cell with an own component is of course no solution)
    Any comment on such an approach?
    Thanks in advance
    Wolfgang R.

    No, it wasn't the custom JTable extension.
    By entering a cell a popup will be shown for a short moment. This is only by using Windows L&F (not Metal). Within the L&F a togglePopup() is called which may cause this problem.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.util.EventObject;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.UIManager;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    public class JTableExt extends JTable {
         public static class ComboBoxEnumRenderer extends JComboBox implements
                   TableCellRenderer {
              public ComboBoxEnumRenderer() {
                   setEditable(false);
                   setBackground(Color.WHITE);
              public Component getTableCellRendererComponent(JTable table, Object value,
                        boolean isSelected, boolean hasFocus, int row, int column) {
                   this.removeAllItems();
                   this.addItem(value);
                   return this;
         public static class ComboBoxEnumEditor extends DefaultCellEditor {
              private static String[] values = null;
              public ComboBoxEnumEditor() {
                   super(new JComboBox());
                   values = new String[50000];
                   for (int i = 0; i < values.length; i++) {
                        values[i] = "row_" + i;
              public Component getTableCellEditorComponent(JTable table, Object value,
                        boolean isSelected, int row, int column) {
                   JComboBox combo = (JComboBox) getComponent();
                   combo.removeAllItems();
                   for (int i = 0; i < values.length; i++) {
                        combo.addItem(values);
                   combo.setSelectedIndex(0);
                   return super.getTableCellEditorComponent(table, value, isSelected, row,
                             column);
         public JTableExt() {
              super();
              init();
         // invoke editor on cell entry
         public void changeSelection(final int row, final int column, boolean toggle,
                   boolean extend) {
              super.changeSelection(row, column, toggle, extend);
              if (editCellAt(row, column))
                   getEditorComponent().requestFocusInWindow();
         private void init() {
              setDefaultEditor(Object.class, new ComboBoxEnumEditor());
              setDefaultRenderer(Object.class, new ComboBoxEnumRenderer());
         private static void setUI() {
              String lnfName = "";
              //lnfName = "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel";
              lnfName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
              try {
                   UIManager.setLookAndFeel(lnfName);
              } catch (Exception exc) {
         public static void main(String args[]) {
              try {
                   setUI();
                   javax.swing.JFrame frame = new javax.swing.JFrame();
                   frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                   frame.getContentPane().setLayout(new BorderLayout());
                   final JTableExt demo = new JTableExt();
                   Object[][] data = new Object[30][1];
                   demo.setModel(new DefaultTableModel(data, new String[] { "first column" }));
                   frame.getContentPane().add("Center", new JScrollPane(demo));
                   frame.setSize(600, 600);
                   frame.setVisible(true);
              } catch (Throwable t) {
                   System.exit(0);
    //end

  • JComboBox in JTable to activate when double-click instead of single-click

    I like to know if it is possible to change the default behaviour of JComboBox within the JTable,
    such that instead of single click on the JTable cell for the combo box's popup to appear, I double click on it instead.
    If it is possible please give some advice.
    Thanks.

    I couldn't get to settings because I couldn't scroll and don't know where that is located. I just saw a similar question from someone else. Three clicks on home button worked to turn off voiceover !! Phew!

  • JTable - JComboBox/List - JTable

    My target: I would like to have multiple columns in my comboBox or list. When I choose one item, the result would be just a single column but not all columns. Moreover, the whole comboBox is actually one cell within a JTable. i.e. when I click one cell of a jtable, it shows a comboBox.
    I have searched this forum but just found some ways to get multiple columns in comboBox, and it seem no one has tried to include it in a JTable cell. I just wonder if anyone can help and it would be thankful.

    Let me post the code here:
    //the init of comboBox model within jtable here
         private void initSupplierCombo(TableColumn col){
           String query = "select supplier_no, supplier_name from supplier_master group by supplier_no,supplier_name;";
           JComboBox comboBox = new JComboBox();
           Vector supplierList = itemDB.getComboResults(query);
           try {
             comboBox.setModel(new ResultSetComboBoxModel(supplierList));
             col.setCellEditor(new DefaultCellEditor(comboBox));
             DefaultTableCellRenderer renderer =
                 new DefaultTableCellRenderer();
             renderer.setToolTipText(
                 "Click for combo box & choose");
             col.setCellRenderer(renderer);
             //Set up tool tip for the sport column header.
             TableCellRenderer headerRenderer = col.getHeaderRenderer();
             if (headerRenderer instanceof DefaultTableCellRenderer) {
               ( (DefaultTableCellRenderer) headerRenderer).setToolTipText(
                   "Click to see a list of choices");
           catch (Exception e) {
             e.printStackTrace();
    //ResultSetComboBoxModel
    import javax.swing.*;
    import java.sql.*;
    import java.util.Vector;
    public class ResultSetComboBoxModel extends ResultSetListModel
        implements ComboBoxModel
        protected Object selected = null;
        public ResultSetComboBoxModel(Vector columnResults) throws Exception {
            super(columnResults);
        public Object getSelectedItem() {
          return selected;
        public void setSelectedItem(Object o) {
            if(o==null)
              selected = o;
            else{
              String value = (String) o;
              selected = (Object)(value.substring(0,value.lastIndexOf("  //  ")));
    //ResultSetListModel
    import javax.swing.*;
    import java.util.*;
    import java.sql.*;
    public class ResultSetListModel extends AbstractListModel {
        List values = new ArrayList();
        public ResultSetListModel(Vector columnResults) throws Exception {
          for(Iterator item = columnResults.iterator();item.hasNext();){
            String[] value  = (String[])item.next();
            values.add(value[0] + "  //  " + value[1]);
        public int getSize() {
            return values.size();
        public Object getElementAt(int index) {
          return values.get(index);
    }

  • Not Updating the Values in the JComboBox and JTable

    Hi Friends
    In my program i hava Two JComboBox and One JTable. I Update the ComboBox with different field on A Table. and then Display a list of record in the JTable.
    It is Displaying the Values in the Begining But when i try to Select the Next Item in the ComboBox it is not Updating the Records Eeither to JComboBox or JTable.
    MY CODE is this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.DefaultComboBoxModel.*;
    import javax.swing.table.*;
    import java.sql.*;
    import java.util.*;
    public class SearchBook extends JDialog implements ActionListener
         private JComboBox comboCategory,comboAuthor;
         private JSplitPane splitpane;
         private JTable table;
         private JToolBar toolBar;
         private JButton btnclose, btncancel;
         private JPanel panel1,panel2,panel3,panel4;
         private JLabel lblCategory,lblAuthor;
         private Container c;
         //DefaultTableModel model;
         Statement st;
         ResultSet rs;
         Vector v = new Vector();
         public SearchBook (Connection con)
              // Property for JDialog
              setTitle("Search Books");
              setLocation(40,110);
              setModal(true);
              setSize(750,450);
              // Creating ToolBar Button
              btnclose = new JButton(new ImageIcon("Images/export.gif"));
              btnclose.addActionListener(this);
              // Creating Tool Bar
              toolBar = new JToolBar();
              toolBar.add(btnclose);
              try
                   st=con.createStatement();
                   rs =st.executeQuery("SELECT BCat from Books Group By Books.BCat");
                   while(rs.next())
                        v.add(rs.getString(1));
              catch(SQLException ex)
                   System.out.println("Error");
              panel1= new JPanel();
              panel1.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.HORIZONTAL;
              lblCategory = new JLabel("Category:");
              lblCategory.setHorizontalAlignment (JTextField.CENTER);
              c.gridx=2;
              c.gridy=2;
              panel1.add(lblCategory,c);
              comboCategory = new JComboBox(v);
              comboCategory.addActionListener(this);
              c.ipadx=20;
              c.gridx=3;
              c.gridwidth=1;
              c.gridy=2;
              panel1.add(comboCategory,c);
              lblAuthor = new JLabel("Author/Publisher:");
              c.gridwidth=2;
              c.gridx=1;
              c.gridy=4;
              panel1.add(lblAuthor,c);
              lblAuthor.setHorizontalAlignment (JTextField.LEFT);
              comboAuthor = new JComboBox();
              comboAuthor.addActionListener(this);
              c.insets= new Insets(20,0,0,0);
              c.ipadx=20;
              c.gridx=3;
              c.gridy=4;
              panel1.add(comboAuthor,c);
              comboAuthor.setBounds (125, 165, 175, 25);
              table = new JTable();
              JScrollPane scrollpane = new JScrollPane(table);
              //panel2 = new JPanel();
              //panel2.add(scrollpane);
              splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,scrollpane);
              splitpane.setDividerSize(15);
              splitpane.setDividerLocation(190);
              getContentPane().add(toolBar,BorderLayout.NORTH);
              getContentPane().add(splitpane);
         public void actionPerformed(ActionEvent ae)
              Object obj= ae.getSource();
              if(obj==comboCategory)
                   String selecteditem = (String)comboCategory.getSelectedItem();
                   displayAuthor(selecteditem);
                   System.out.println("Selected Item"+selecteditem);
              else if(obj==btnclose)
                   setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
              else if(obj==comboAuthor)
                   String selecteditem1 = (String)comboAuthor.getSelectedItem();
                   displayavailablity(selecteditem1);
                   //System.out.println("Selected Item"+selecteditem1);
                   System.out.println("Selected Author"+selecteditem1);
         private void displayAuthor(String selecteditem)
              try
              {     Vector data = new Vector();
                   rs= st.executeQuery("SELECT BAuthorandPublisher FROM Books where BCat='" + selecteditem + "' Group By Books.BAuthorandPublisher");
                   System.out.println("Executing");
                   while(rs.next())
                        data.add(rs.getString(1));
                   //((DefaultComboBoxModel)comboAuthor.getModel()).setVectorData(data);
                   comboAuthor.setModel(new DefaultComboBoxModel(data));
              catch(SQLException ex)
                   System.out.println("ERROR");
         private void displayavailablity(String selecteditem1)
                   try
                        Vector columnNames = new Vector();
                        Vector data1 = new Vector();
                        rs= st.executeQuery("SELECT * FROM Books where BAuthorandPublisher='" + selecteditem1 +"'");     
                        ResultSetMetaData md= rs.getMetaData();
                        int columns =md.getColumnCount();
                        String booktblheading[]={"Book ID","Book NAME","BOOK AUTHOR/PUBLISHER","REFRENCE","CATEGORY"};
                        for(int i=1; i<= booktblheading.length;i++)
                             columnNames.addElement(booktblheading[i-1]);
                        while(rs.next())
                             Vector row = new Vector(columns);
                             for(int i=1;i<=columns;i++)
                                  row.addElement(rs.getObject(i));
                             data1.addElement(row);
                             //System.out.println("data is:"+data);
                        ((DefaultTableModel)table.getModel()).setDataVector(data1,columnNames);
                        //DefaultTableModel model = new DefaultTableModel(data1,columnNames);
                        //table.setModel(model);
                        rs.close();
                        st.close();
                   catch(SQLException ex)
    }Please check my code and give me some Better Solution
    Thank you

    You already have a posting on this topic:
    http://forum.java.sun.com/thread.jspa?threadID=5143235

  • Using KeyMap in Editable JComboBoxes and JTable

    I am using Keymapping for JTextFields. It works fine ! I am interested in extending the keymap feature to JComboBoxes and JTable.

    if you want to do the keymapping inside the editable component of the combobox or the table, make sure you apply it on the editor component.e.g. comboBox.getEditor().getEditorComponent() and table.getCellEditor().getTableCellEditorComponent().

  • Multiple keystrokes selection for a JComboBox in JTable

    Has anyone used multiple keystrokes selection in a JComboBox inside JTable before? I can get it done outside JTable by using: http://javaalmanac.com/egs/javax.swing/combobox_CbMultiKey.html
    Looks like JTable has all kinds of problems to support JComboBox.
    Suggestions?
    Thanks,
    James

    If I read you right, you want to use a multiple keystroke combo box as an editor in a JTable?
    If you create the JComboBox as you would like it and then install it as an editor in the column(s) JTable the editor will work like the JComboBox
    Example:
    //- you would have that keyselection Manager class
    // This key selection manager will handle selections based on multiple keys.
    class MyKeySelectionManager implements JComboBox.KeySelectionManager {    ....    };
    //- Create the JComboBox with the multiple keystroke ability
    //- Create a read-only combobox
    String[] items = {"Ant", "Ape", "Bat", "Boa", "Cat", "Cow"};
    JComboBox cboBox = new JComboBox(items);
    // Install the custom key selection manager
    cboBox.setKeySelectionManager(new MyKeySelectionManager());
    //- combo box editor for the JTable
    DefaultCellEditor cboBoxCellEditor = new DefaultCellEditor(cboBox);
    //- set the editor to the specified COlumn in the JTable - for example the first column (0)
    tcm.getColumn(0).setCellEditor(cboBoxCellEditor); Finally, it may be necessary to to put a KeyPressed listener for the Tab key, and if you enter the column that has the JComboBox:
    1) start the editting
    table.editCellAt(row, col);2) get the editor component and cast it into a JComboBox (in this case)
    Component comp = table.getEditorComponent();
    JComboBox cboComp = (JComboBox) comp;3) give this compent the foucus to do its deed     
    cboComp.requestFocus();Hope this helps!
    dd

  • How to put JComboBox in JTable?

    I'm trying to put JComboBox in JTable, the following is my table model. The problem is that it doesn't display a JComboBox but a string of it, something like "MyTableModel$JComboBox....". Any help would be appreciated.
    class MyModel extends AbstractTableModel {
    String[] columnNames = {"Column One", "Column One"};
    String[] boxItem = {"Item One", "Item Two"};
    String[] rows = {"Row One", "Row Two"};
    JComboBox[] boxes = {
    new JComboBox(boxItem),
    new JComboBox(boxItem)
    Object[][] data = new Object[][]{rows, boxes};
    public Object getValueAt(int row, int col) {
    return data[col][row];
    }

    Hi,
    the TableModel is the wrong place to put the combo box. A model is just a representation for the data displayed in the table.
    A combo box, on the other hand, is a certain way for the user to edit the values in the table (and in the model). To change the way a user edits in a table you have to set the TableCellEditor. You can do this for the whole table or for a certain column.
    // in the JTable's constructor or init method
    // to set JComboBox in 2nd column
    // get 2nd column
    TableColumn column = myTable.getColumnModel().getColumn(1);
    // create combo box
    JComboBox combo = new JComboBox();
    combo.add("ItemOne");
    combo.add("ItemTwo");
    // set as editor for the column
    DefaultCellEditor editor = new DefaultCellEditor(combo);
    column.setCellEditor(editor);This is just an example. Try it w/ a simple table.

  • Editable JComboBox in JTable

    There is a bug in Jdk1.5 (bug#4684090) - When TAB out from Editable Jcombobox in JTable, the focus is moved to outside JTable instead of next cell.
    What is the best workaround for thsi bug.
    Thanks,
    VJ

    I was using java 1.5.0_06 in my application and I had this problem
    When I upgraded to java 1.6.0_01, I no longer had this issue.
    This seems to be a bug in 1.5 version of Java that has been fixed in 1.6
    thanks,

  • Placing JComboBox in JTable ColumnHeader

    Can any one help me on how to place a JComboBox in JTable ColumnHeader....?

    try this:
    package ComponentDisplayer;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    class JComponentCellRenderer implements TableCellRenderer
        public Component getTableCellRendererComponent(JTable table, Object value,
              boolean isSelected, boolean hasFocus, int row, int column) {
            return (JComponent)value;
    }and
    package ComponentDisplayer;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Pable
         public static void main(String[] args)
              JFrame frame = new JFrame("Table");
              frame.addWindowListener( new WindowAdapter() {
                   public void windowClosing(WindowEvent e)
                        Window win = e.getWindow();
                        win.setVisible(false);
                        win.dispose();
                        System.exit(0);
              JTable table = new JTable(3,2);
                 TableCellRenderer renderer = new JComponentCellRenderer();
                  TableColumnModel columnModel = table.getColumnModel();
                  TableColumn column0 = columnModel.getColumn(0);
                  TableColumn column1 = columnModel.getColumn(1);
                  column0.setHeaderRenderer(renderer);
                  JComboBox jb=new JComboBox();
                  jb.insertItemAt("well", 0);
                  jb.insertItemAt("done", 1);
                  column0.setHeaderValue(jb);
                  column1.setHeaderRenderer(renderer);
                  column1.setHeaderValue(new JComboBox());
              table.setAutoResizeMode(table.AUTO_RESIZE_ALL_COLUMNS);
              table.setSize(900, 1200);
              JScrollPane sp = new JScrollPane(table);
              table.setColumnSelectionAllowed(false);
             table.setRowSelectionAllowed(true);
              frame.getContentPane().add( sp );
              frame.pack();
              frame.setVisible(true);
              //frame.show();
    }as you can see adding it is not that hard but you cannot interact with them because if my memory serves well, tableheaders cannot have focus by default. So you gotta write your own implementation of header (may be using sth like: )public class MyTableHeaderRenderer extends JComponent implements
              TableCellRenderer {
         public MyTableHeaderRenderer() {
              // TODO Auto-generated constructor stub
         public Component getTableCellRendererComponent(JTable arg0, Object arg1,
                   boolean arg2, boolean arg3, int arg4, int arg5) {
              // TODO Auto-generated method stub
              return (JComponent)arg1;
         }and then use this as default renderer in your implementation.)
    E,ther you have to handle setfocus thing or keep track of mouse events
    I hope this helps

  • Jcombobox inside jtable

    I have a jcombobox inside jtable.now i want to access its items by keys only..without using F2 key.for example if i press 's' key..the whole combobox shud popup and value 'string' is selected.please help me regarding this.

    I am not sure if I understand your question exactly. Your table's row height is not high enough so you may need to add a line of code like:
            table.setRowHeight(table.getRowHeight() + 4);to solve your problem.

  • How can you use the Keyboard for a JComboBox within a JTable without F2

    I am brand new to Java and I can't seem to figure this out. I have a JTable with 4 columns. The first column is a jCheckBox which is working fine. The other three are JComboBoxes. They work fine when you click them and select from the list, but our end users only want to navigate with the keyboard. They want to be able to tab to the column and just start typing the first letter of the item that they want to choose from the list and have that pop up the list and scroll to the first item in the list that starts with the letter the typed. Does anyone know how to do this? I have been playing with this for a week now and I can't seem to make it work. Please help. Below is the code for my table. Any help would be appreciated greatly. Thanks,
    Lisa
         private void LoadSTCGTable(){
         //Connect to database
            try {
                    connection = ConnecttoDB.connect();
                    // Tell me why I couldn't connect
                } catch (ClassNotFoundException ex) {
                    ex.printStackTrace();
                } catch (SQLException ex) {
                    ex.printStackTrace();
         try {
                // Get listing of Squad Types
                tblSTCG.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {new Boolean(false), null, null, null},
                new String [] {
                    "SELECT", "SQUAD TYPE", "SQUAD CLASS", "SQUAD GROUP"
              //Add Checkbox column
               tblSTCG.getColumnModel().getColumn(0).setCellEditor(tblSTCG.getDefaultEditor(Boolean.class));
               tblSTCG.getColumnModel().getColumn(0).setCellRenderer(tblSTCG.getDefaultRenderer(Boolean.class));      
               tblSTCG.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
               Whichquerytoread = 1;
               GetSql();
               sql = textfileinfo;
               stmt = connection.createStatement();
               rs = stmt.executeQuery(sql);
               md = rs.getMetaData();
               typelist = new ArrayList();
               // Loop Through Results
               typelist.add(new PairedDescriptionCodeDesc("",""));
               while (rs.next())
                  int i = 1;
                 typelist.add( new PairedDescriptionCodeDesc(rs.getString(2),rs.getString(1)));
              s1 = new TreeSet(typelist);
              typelist = new ArrayList(s1);
              AllTypeList = new PairedDescriptionCodeDesc[typelist.size()];
              for (int i = 0; i<typelist.size(); i++)
                 AllTypeList=(PairedDescriptionCodeDesc)typelist.get(i);
    rs.close();
    catch (SQLException ex) {
    ex.printStackTrace();
    Vector typedata = new Vector();
    for (int i=0;i<typelist.size();i++)
    typedata.addElement((PairedDescriptionCodeDesc)typelist.get(i));
    cmboType = new JComboBox();
    cmboType.setModel(new DefaultComboBoxModel(typedata));
    cmboType.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    cmboType = new JComboBox(AllTypeList);
    cmboType.setBorder(BorderFactory.createEmptyBorder());
    squadcol = tblSTCG.getColumnModel().getColumn(1);
    DefaultCellEditor cmboTypeEditor = new DefaultCellEditor(cmboType);
    cmboTypeEditor.addCellEditorListener(new NewRowCellEditorListener(tblSTCG));
    squadcol.setCellEditor(cmboTypeEditor);
    try {
    // Get listing of Squad Class
    Whichquerytoread = 2;
    GetSql();
    sql = textfileinfo;
    stmt = connection.createStatement();
    rs = stmt.executeQuery(sql);
    md = rs.getMetaData();
    classlist = new ArrayList();
    // Loop Through Results
    classlist.add(new PairedDescriptionCodeDesc("",""));
    while (rs.next())
    classlist.add(new PairedDescriptionCodeDesc(rs.getString(2),rs.getString(1)));
    s1 = new TreeSet(classlist);
    classlist = new ArrayList(s1);
    AllClassList = new PairedDescriptionCodeDesc[classlist.size()];
    for (int i = 1; i<classlist.size(); i++)
    AllClassList[i]=(PairedDescriptionCodeDesc)classlist.get(i);
    rs.close();
    catch (SQLException ex) {
    ex.printStackTrace();
    Vector classdata = new Vector();
    for (int i=0;i<classlist.size();i++)
    classdata.addElement((PairedDescriptionCodeDesc)classlist.get(i));
    cmboClass = new JComboBox();
    cmboClass.setModel(new DefaultComboBoxModel(classdata));
    cmboClass = new JComboBox(AllClassList);
    classcol = tblSTCG.getColumnModel().getColumn(2);
    DefaultCellEditor cmboClassEditor = new DefaultCellEditor(cmboClass);
    classcol.setCellEditor(new DefaultCellEditor(cmboClass));
    cmboClassEditor.addCellEditorListener(new NewRowCellEditorListener(tblSTCG));
    try {
    // Get listing of Squad Group
    Whichquerytoread = 3;
    GetSql();
    sql = textfileinfo;
    stmt = connection.createStatement();
    rs = stmt.executeQuery(sql);
    md = rs.getMetaData();
    grouplist = new ArrayList();
    // Loop Through Results
    grouplist.add(new PairedDescriptionCodeDesc("",""));
    while (rs.next())
    int i = 0;
    grouplist.add( new PairedDescriptionCodeDesc(rs.getString(2), rs.getString(1)));
    s1 = new TreeSet(grouplist);
    grouplist = new ArrayList(s1);
    AllGroupList = new PairedDescriptionCodeDesc[grouplist.size()];
    for (int i = 0; i<grouplist.size(); i++)
    AllGroupList[i]=(PairedDescriptionCodeDesc)grouplist.get(i);
    rs.close();
    catch (SQLException ex) {
    ex.printStackTrace();
    Vector groupdata = new Vector();
    for (int i=0;i<grouplist.size();i++)
    groupdata.addElement((PairedDescriptionCodeDesc)grouplist.get(i));
    cmboGroup = new JComboBox();
    cmboGroup.setModel(new DefaultComboBoxModel(groupdata));
    cmboGroup = new JComboBox(AllGroupList);
    groupcol = tblSTCG.getColumnModel().getColumn(3);
    DefaultCellEditor cmboEditor = new DefaultCellEditor(cmboGroup);
    cmboEditor.addCellEditorListener(new NewRowCellEditorListener(tblSTCG));
    groupcol.setCellEditor(cmboEditor);
    tblSTCG.setShowHorizontalLines(false);
    tblSTCG.setShowVerticalLines(false);
    TableColumnModel columnModel = tblSTCG.getColumnModel();
    TableColumn column;
    tblSTCG.getColumnModel().getColumn(0).setPreferredWidth(5);
    tblSTCG.getColumnModel().getColumn(1).setPreferredWidth(100);
    tblSTCG.getColumnModel().getColumn(2).setPreferredWidth(100);
    tblSTCG.getColumnModel().getColumn(3).setPreferredWidth(100);
    scpSTCG.setViewportView(tblSTCG);
    private class NewRowCellEditorListener implements CellEditorListener
    JTable editingTable;
    public NewRowCellEditorListener(JTable table)
    editingTable = table;
    public void editingStopped(ChangeEvent e)
    if(editingTable.getRowCount() == editingTable.getSelectedRow() + 1)
    ((DefaultTableModel)editingTable.getModel()).addRow(new Object [] {null, null, null, null});
    public void editingCanceled(ChangeEvent e)

    Final Cut Pro menu > Audio / Video Settings... (Cmd Opt Q) will show you al the various presets currently loaded
    Sequence menu > Settings... (Cmd Zero) will show you the current sequence's settings
    Edit > Item Properties > Format... (Cmd 9) will show you the selected clip's properties

  • JComboBox With JTable as Editor

    Hi everybody
    I'm working with JTable and having a ComboBox as first CellEditor. for that purpose i used following code
            cmbFeeType.setModel(new javax.swing.DefaultComboBoxModel(DefaultFee.FeeTypeItemList()));       
            DefaultCellEditor DCEFeeType = new DefaultCellEditor(cmbFeeType);
            DCEFeeType.setClickCountToStart(2);here DefaultFee.FeeTypeItemList is a vector returns array. This is working fine except that the ComboBox remains visible till I dobule clik on a column for editing. Then It becomes invisible and works fine.
    my JComboBox is a seperate Control on a JFrame I do not want to use
    Class FeeTypeEditor extends JComboBox implements TableCellEditoras a ComboBox editor for JTable
    Please Help Me.

    Hi
    I am giving u a sample code which simulate the error
    * TestJTable.java
    * Created on August 5, 2008, 11:05 AM
    package TestJTable;
    import javax.swing.DefaultCellEditor;
    import javax.swing.table.TableColumn;
    * @author  yogi
    public class TestJTable extends javax.swing.JFrame {
        /** Creates new form TestJTable */
        public TestJTable() {
            initComponents();
            DefaultCellEditor ColumnEditor = new DefaultCellEditor(jComboBox1);
            ColumnEditor.setClickCountToStart(2);
            TableColumn column = jTable1.getColumnModel().getColumn(0);
            column.setCellEditor(ColumnEditor);       
        /** 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 Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            jComboBox1 = new javax.swing.JComboBox();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(null);
            jTable1.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"
            jScrollPane1.setViewportView(jTable1);
            getContentPane().add(jScrollPane1);
            jScrollPane1.setBounds(10, 10, 340, 180);
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            getContentPane().add(jComboBox1);
            jComboBox1.setBounds(180, 220, 120, 20);
            pack();
        }// </editor-fold>//GEN-END:initComponents
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    TestJTable TJTable = new TestJTable();
                    TJTable.setExtendedState(MAXIMIZED_BOTH);               
                    TJTable.setVisible(true);
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration//GEN-END:variables
    }Above code is generated by Netbeans IDE 6.0
    My promblem is that when you run the code the combobox JComboBox1 remains visible till i starts to edit the Table after once started editing it disappears.
    I want to avoid this
    thanks in advance

  • AutoComplete JComboBox As JTable cell editor

    Hello, when I try to use AutoComplete JComboBox as my JTable cell editor, I facing the following problem
    1) Exception thrown when show pop up. - Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    2) Unable to capture enter key event.
    Here is my complete working code. With the same JComboBox class, I face no problem in adding it at JFrame. But when using it as JTable cell editor, I will have the mentioned problem.
    Any advice? Thanks
    import javax.swing.*;
    import javax.swing.JTable.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    * @author  yccheok
    public class NewJFrame extends javax.swing.JFrame {
        /** Creates new form NewJFrame */
        public NewJFrame() {
            initComponents();
                    /* Combo Box Added In JFrame. Work as expected. */
                    final JComboBox comboBox = new JComboBox();
                    comboBox.addItem("Snowboarding");
                    comboBox.addItem("Rowing");
                    comboBox.addItem("Chasing toddlers");   
                    comboBox.setEditable(true);
                    comboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
                       public void keyReleased(KeyEvent e) {
                           if(e.getKeyCode() == KeyEvent.VK_ENTER) {
                               System.out.println("is enter");
                               return;
                           System.out.println("typed");
                           comboBox.setSelectedIndex(0);
                           comboBox.showPopup();
                    getContentPane().add(comboBox, java.awt.BorderLayout.SOUTH);
        public JTable getMyTable() {
            return new JTable() {
                 Combo Box Added In JTable as cell editor. Didn't work as expected:
                 1. Exception thrown when show pop up.
                 2. Unable to capture enter key event.
                public TableCellEditor getCellEditor(int row, int column) {
                    final JComboBox comboBox = new JComboBox();
                    comboBox.addItem("Snowboarding");
                    comboBox.addItem("Rowing");
                    comboBox.addItem("Chasing toddlers");   
                    comboBox.setEditable(true);
                    comboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
                       public void keyReleased(KeyEvent e) {
                           if(e.getKeyCode() == KeyEvent.VK_ENTER) {
                               System.out.println("is enter");
                               return;
                           System.out.println("typed");
                           comboBox.setSelectedIndex(0);
                           comboBox.showPopup();
                    return new DefaultCellEditor(comboBox);
        /** 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 Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = getMyTable();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTable1.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"
            jScrollPane1.setViewportView(jTable1);
            getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration                  
    }

    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.

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

Maybe you are looking for

  • Attachment list

    Using PP01 (as well as other transactions) with the 'services for object' option there is sometimes the option to save attachments (word documents, spreadsheets, etc.) in SAP. My question is this - does anyone know where the objects are actually stor

  • True or false template

    hi, i am new to flash ,i am finding difficulty for loading  xml in flash as2 for making true or false template through xml only,can anyone help me out please. thank u.

  • My blackberry curve 8530 shut off and now it doesn't want to completely turn on it stays loading.

    My blackberry curve 8530 shut off and now it doesn't want to completely turn on it stays loading.

  • How to filter complex data using pl/sql

    Hello, i have to filter some data from the table with 1millions rows in it. here the requirement for example table is TEST id type 1 a 1 a 1 b 2 c 33 b 33 b 33 c 33 d 5 c 5 c now i just want to display the results which contains type c only if id is

  • Serial # doesn't work Premiere Elements 12

    Just bought the product can't install Got the numbers and installed Adopbe photoshop elements 12 but the serical # for Premiere Elements doesn't work