Focus for JCombobox in the JTable

Hi GentleMen,
I have one combobox in the JTable and when i change the item
in the combobox two messages poped up and item is set to
the same previous item.Here my problem is that when i get to the
first item the focus not being on the same ombobox . What might be the
problem. Help me with the example code.
Thanks & Regards,
Pothanumara

No idea what you are asking.
Here is an example that uses a different combo box for each row:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Similar Messages

  • JComboBox in the JTable Header - TableCellEditor problem

    Hi,
    I have added JComboBox into the JTableHeader. But I can't Edit that combobox. It is looking like an icon. I have added JPanel into the JTable Header Row. In JPanel i have added one JLable and JComboBox.
    Please any one of you give me the solution.
    Thanks,
    Shrini V.

    The table will display what ever value it has in its model. When you add the row, there is no data in the second column. You'll have to supply it.
    public void insertMyRowCombo (Object [] r,
                                      JComboBox c,
                                      JTable t) {
           // {"rut", "puntaje cas", "beneficio", "fecha inicio", "fecha termino", "monto"};
            DefaultTableModel tm = (DefaultTableModel) t.getModel();
            tm.addRow(r);
            TableColumn col = t.getColumnModel().getColumn(2);
            col.setCellEditor(new DefaultCellEditor(c));
            tm.setValueAt( c.getItemAt(0), 0, 2); //manually supply the value to col 2
        }ICE

  • Unable to sort the content of the jTable

    Hi all ,
    I m using this code for sorting in the Jtable
    JTable table = new JTable(new MyTable());
            table.setPreferredScrollableViewportSize(new Dimension(500,500));
            table.setFillsViewportHeight(true);
            table.setAutoCreateRowSorter(true);Where MyTable --> is the AbstractTableModel.
    Im using LookAndFeel -- com.birosoft.liquid.
    With this lookandfeel , when I click the columnheader , it is not sorting :(
    But when I change the lookandfeel as default it is working.
    Can anybody tell what Im doing wrong. or is there any method through which I can sort with com.birosoft lookandfeel
    Thanks and regards
    Anshuman Srivastava

    Thaks for advice .
    I have checked their API , theere is some bug for sorting it.
    So what I have done . this JTable I opened in a Jdialog , for which I have made the lookandfeel as default.
    This code when I making the JDialog
    try{
                   UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              catch(Exception e){}
              panel = new JPanel();Now when closing the JDialog , Im making resetting the lookandfeel
    @Override
                   public void windowClosing(WindowEvent e) {
                        // TODO Auto-generated method stub
                        try{
                             UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
                             SwingUtilities.updateComponentTreeUI(parent);
                             parent.pack();
                             parent.repaint();
                        catch(Exception ecc){}
                   }where in this parent is the frame over which I have opened the JDilaog.
    But after it didnt reset the lookandfeel for the other component
    Thanks and regards
    Anshuman Srivastava

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

  • Different JCombobox items in JTable for the same column

    Hello Everyone,
    I am reading from a file and displaying in a JTable. I want all cells in a specific column to be JComboBoxes but the items in the JComboBox differ from one cell to another, how can this be achieved?
    The following is a snippet from the Sun tutorials,
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Knitting");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Pool");
    comboBox.addItem("None of the above");
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
    And hence every cell in the sportColumn has the exact same set of options in the JComboBox which is not what I want since I read from an external file.
    Any help or sample code would be highly appreciated.
    Thank you in advance

    Override getCellEditor(int row, int column) in JTable to control which editor gets used for which cell.

  • Keyboard Access For a Column in JTable with default editor as JComboBox

    I want to get Key board access for a column in JTable.
    The user should be able to select from a drop down list for the column with default
    editor set as JComboBox.
    Presently,it works fine with mouse,also I am able to focus it with Keyboard using
    ALT+Up keys,but how to make drop down list appear.
    Plz help,it's urgent.
    Thanks in Advance

    Hi,
    In addition to setting DO_SUM = 'X' you need to specify function in H_FTYPE field. It should be set to 'AVG' in your case.
    ls_fielcat-do_sum = 'X'.
    ls_fieldcat-h_ftype = 'AVG.

  • How can I give different Editors in the same column for the jTable?

    I am having a JTable with 2 columns and 10 rows. In the 2nd column, for the first 2 rows
    I need to show JCheckBox, for nect 2 JComboBox and for remaining JTextField as the editor.
    How can I do this. Thanks in Advance.

    Remember, the parent class of a cell renderer does NOT have to be a Component itself. Most do simply because the end result of the getCellRenderer call is the component itself.
    Create 3 cell renderers, one based off of the checkbox, one based off the combobox, one based off of Object. The Object based one will hold instances of the other two renderers and will be the actual renderer supplied to the JTable. When called, based on the row, it will forward the call to the to the appropriate renderer and return the result of the call.
    Technically, the internal components do not NEED to be renderers themselves, but doing so makes it a lot easier to test them independently of the combined renderer.

  • EditCellAt() with mouseclick is not working for first row of the jtable

    Hi All,
    I have extended JTable.changeSelection() & editCellAt() methods to force the text to select when focus is brought to the cell.
    I have a page which has both editable and non-editable columns. when I do a mouse click on FIRST ROW of the editable cell and type the value, The value is not displayed in the cell. when I click on any other editable field in the page, The typed value is displayed in the cell. In the first row of the cell, only the first attempt is not working. When I remove the editCellAt() call in changeSelection(), it works as expected.
    But, If I reach the FIRST ROW editable cell using TAB key instead of Mouse click and type the value, its working fine.
    Kindly suggest me what could be the problem in my code. I think something wrong in editcellat() or mouseclicked/released or focusgained in our versions of JTable or jtextfield.
    Kindly let me know if you need any more functions of my version of implementation.
    Thanks In advance.
    My JTable Version of editCellAt:
         public boolean editCellAt(int row, int column, EventObject e) {
              try {
                   if (getCellEditor() != null && !getCellEditor().stopCellEditing()) {
                        return false;
                   if (!isCellEditable(row, column)) {
                        return false;
                   if (isShowStarRow() /*&& !starRowAdded*/) {
                        VSDataControl ds = getDataSource();
                        if (ds != null) {
                             VSResultSet rs = ds.getResultSet();
                             if (rs != null) {
                                  if (row == rs.getRowCount()) { // This is the star row
                                       // Go to the last record
                                       if (row > 0) {
                                            try {
                                                 rs.getRowAt(row + 1, true);
                                                 rs.last();
                                            } catch (Exception ex) {
                                                 return false;
                                       if (ds.insert() == null) {
                                            return false;
                                       currentRow = row + 1;
                                       starRowAdded = true;
                   TableCellEditor editor = getCellEditor(row, column);
                   if (editor != null && editor.isCellEditable(e)) {
                        editorComp = prepareEditor(editor, row, column);
                        if ( editorComp instanceof VSGridChoice && lastKeyEvent != null ) {
                             VSGridChoice choice = (VSGridChoice) editorComp;
                             choice.handleMissingCharEvent( lastKeyEvent );
                        if (editorComp instanceof VSChoiceBase && lastKeyEvent != null ) {
                             VSChoiceBase hack = (VSChoiceBase)editorComp;
                             hack.addMissingChar(lastKeyEvent);
                        lastKeyEvent = null;
                        if (editorComp == null) {
                             removeEditor();
                             return false;
                        editorComp.setBounds(getCellRect(row, column, false));
                        add(editorComp);
                        editorComp.validate();
                        editorComp.requestFocus();
                        setCellEditor(editor);
                        setEditingRow(row);
                        setEditingColumn(column);
                        editor.addCellEditorListener(this);
                        return true;
                   return false;
              } catch (Exception ex) {
                   showValidationError(e, ex);
                   return false;
         public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
              super.changeSelection(rowIndex, columnIndex, toggle, extend);
                    editCellAt(rowIndex, columnIndex);
                           if (getEditorComponent() != null)
                   if (getEditorComponent() instanceof CustomJTextField)
                        ((CustomJTextField)getEditorComponent()).selectAll();
          }

    i will suggest you to override your requetFocus()
    like.
    public void requestFocus()
            super.requestFocus(); // may be panel or container.
            textPane.setSelectionStart(0); // textpane is the editor for the cell.
            textPane.setSelectionEnd(textPane.getText().length());
        } Gud luck.

  • Update JTable when an item is selected in a JComboBox inside the same JTabl

    I created a JTable with a lookup JComboBox. I want to update values from the table when an item is selected in the ComboBox.
    I tried all the events posible in JComboBox, but I can not fire to update the JTable.
    Please if you have a how-to, (source) will help. Thanks.
    Regards,
    -Rory

    I tried that. But it only fires when the JComboxBox, lost the focus. And not in the "itemChange" event. How to do it width that event?
    I want something like "intemChange" event, to fire the JTable.fireTableChangeUpdate(); ... I send the code.
    * @author rory
    public class PeriodenDauerGrid extends JPortSimTable implements Serializable, ActionListener {
         * generated id
        private static final long serialVersionUID = -5270969898251578932L;
        public PeriodenDauerGrid() {
            super();
        @Override
        protected void initComponent() {
            super.initComponent();
            setModel(new PeriodenDauerGridTableModel());
            setDefaultEditor(String.class, new PeriodenCellEditor(this));
            setDefaultRenderer(String.class, new PeriodenCellRenderer());
        public void actionPerformed(ActionEvent e) {
            // HERE should fire the table update.
            // JOptionPane.showMessageDialog(null, "HOLITA!");
            PeriodenDauerGridTableModel model = (PeriodenDauerGridTableModel) getModel();
            model.fireTableDataChanged();
            updateUI();
    class PeriodenCellRenderer extends JLabel implements TableCellRenderer {
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            setHorizontalTextPosition(SwingConstants.CENTER);
            setHorizontalAlignment(SwingConstants.CENTER);
            if (row == 1) {
                setOpaque(true);
                setBackground(GuiConstants.PANEL_COLOR);
            } else {
                setOpaque(false);
                setBackground(GuiConstants.CELL_EDITOR_COLOR);
            if (value instanceof Date) {
                Date n = (Date) value;
                // String.format(format, args)
                String s = String.format("%1$td.%1$tm.%1$tY", (Date) value);
                setText(s);
            } else {
                setText(value == null ? "" : value.toString());
            return this;
    class PeriodenCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JComboBox combo = new JComboBox(new String[] { "7", "84", "182", "364" });
        private JTable table = null;
        public PeriodenCellEditor(PeriodenDauerGrid table) {
            combo.addActionListener(table);
            this.table = table;
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            combo.setSelectedItem(value.toString());
            return combo;
        public Object getCellEditorValue() {
            return combo.getSelectedItem();
    }

  • Can a ReadOnly-JTextField get the Focus for a Copy action?

    Until JDK 1.3 a JTextField can be focusable and selectable, also the JTextField
    is not editable. So the user can Copy (with Ctrl-C) the displayed text to an other application.
    With JDK 1.4 the user cannot select the JTextField, if the Field is not editable.
    How I can the JTextField set to selectable (or focusable) in not editable state?
    thanks for suggestions
    Roland

    I suppose a workaround would be to make the JTextField editable, and to assign a DocumentListener that throws away all attempted updates to the content. Look in the API documentation for JTextField for an example of a DocumentListener that controls the content (you would just override insertString and deleteString (?) to do nothing).

  • I try to create an html for IPad. The html page contains an element overlapping a video, now it works as for view but the focus is still with video. This denies the event of overlapping element from occuring. Can please anyone help to solve this issue?

    I try to create an html for IPad. The html page contains an element overlapping a video, now it works as for view but the focus is still with video. This denies the event of overlapping element from occuring. Can please anyone help to solve this issue?

    Hello,
    '''Try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
    ''(If you're not using it, switch to the Default theme.)''
    * On Windows you can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * On Mac you can open Firefox 4.0+ in Safe Mode by holding the '''option''' key while starting Firefox.
    * On Linux you can open Firefox 4.0+ in Safe Mode by quitting Firefox and then going to your Terminal and running: firefox -safe-mode (you may need to specify the Firefox installation path e.g. /usr/lib/firefox)
    * Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
    [[Image:FirefoxSafeMode|width=520]]
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    [[Image:Safe Mode Fx 15 - Win]]
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    ''When you figure out what's causing your issues, please let us know. It might help other users who have the same problem.''
    Thank you.

  • During video recording the auto focus doesn't work automatically!i must have a tap on the display for to use the autofocus! Ihave an iphone 4s

    during video recording the auto focus doesn't work automatically!i must have a tap on the display for to use the autofocus! Ihave an iphone 4s

    I know.  Same issue here.  When I'm not recording but have the video camera on, the autofocus works fine.  As soon as I tap the record button and recording starts, the focus is locked until I tap on the screen to focus.  I haven't used the camera all that much because of this problem.

  • All focused for the movie The Amazing Spider-Man 2

    All focused for the movie The Amazing Spider-Man 2
    https://drive.google.com/forms/d/1yLXR8rBm1cHDSTRBL9EMbXGxMyjjYxfU804QLRPMIIw/viewform
    http://theamazingspiderman2now.wordpress.com/
    http://hdmedia.uservoice.com/knowledgebase/articles/352801-watch-the-amazing-spider-man-2-online-all-resource
    studios, at one point having James Cameron to direct, before being secured by Sony Pictures Entertainment. Sony hired comic

    Dolby Laboratories is potables the silver screen world with its new Dolby Atmos technology, the simply object-based cinema sound platform available in these times. Dolby Atmos unleashes the capability of sound in storytelling by outfitting sound experts
    the prominent exception to easily designation or feat medicine sounds anywhere in the movie theatre, not just where there happen to be speakers. The counting is what moviegoers venture avowed as the most engrossing and lifelike cinema sound experience ever.
    Introduced in April 2012, Dolby Atmos has been embraced by all the greatest Hollywood studios, six Doctrine Award® winning directors, and 12 Academy Award® winning sound mixers, among others. More than 450 Dolby Atmos screens have been installed or committed
    to in 40 countries with more than 150 exhibitors. More than 100 films from 10 selection countries—representing a adequate range of genres from order thrillers and spry fa to spirits and horror—have been or are scheduled to be released with Dolby Atmos sound
    since the first film debuted in June 2012.
    Dolby Atmos has customary detailed skill rewards from both the Hollywood Post Alliance and the Cinema Audio Federation. As the inventors of the only object-based audio scheme old in the cinema today, Dolby is efficacious in all respects with the Society of
    Manner Picture and Compel Engineers in driving adoption of standards for object-based audio.

  • Since upgrading to Mavericks from time to time the focus for the cursor is misplaced when scrolling

    Since upgrading to Mavericks, from time to time the focus for scrolling is misplaced. If I click into the list of emails, the mail message in preview scrolls. If I click into the mailboxes column, the list of emails in my inbox scrolls. Have anyone else seen this issue?

    Since upgrading to Mavericks, from time to time the focus for scrolling is misplaced. If I click into the list of emails, the mail message in preview scrolls. If I click into the mailboxes column, the list of emails in my inbox scrolls. Have anyone else seen this issue?

  • Event handling of JComboBox outside a JTable

    Hi to All,
    I've a question about JTables and JComboBoxes... I'm working on a application which holds a JTable and several JButtons and JCombBoxes. When the user clicks on a cell in the JTable, this cell will get the focus and the text will be highlighted. An action will be performed when the user clicks on a JButton (this just works fine). When the user clicks on a JComboBox also an action must be performed... but this won't work. I guess it won't work because of the JComboBox will draw a popup, and this popup will be cover the cell with the focus...
    I could not catch any event of the JComboBox...
    How can I check for a click on a JComboBox when an other component (JTable cell) has the focus?
    Thnx,

    Hi Swetha,
    Button controls in a table are available only in version 2.0 of the .NET PDK.
    In order to use Button in a table and handle its events u will have to upgrade.
    Further information about using input controls in a table is available in the How to section of the PDK documentation.
    Thanks, Reshef

Maybe you are looking for