JTable tab key navigation with JComboBox Cell Editors in Java 1.3 & 1.4

Hello - this is one for the experts!
I have a JTable which has an editable JComboBox as one of the cell editors for a particular column. Users must be able to navigate through the table using the tab key. After editing a cell a single tab should advance the cell selection to the next column and then the user should just be able to start typing to populate the cell.
However, i've come across some really frustrating differences between the Swing implementation of JDK1.3.1_09 and JDK 1.4.2_04 which means this behaviour is very different between versions!....
1. Editing Cells and then advancing to the next column using tab.
Using standard cell editors (based around JTextFields) in 1.3.1 the user has to press tab twice to traverse to the next column after editing. However, in 1.4.2 a single tab key is enough to move to the next column after editing.
2. Editable JComboBox editors and and advancing to the next column using tab.
Using JDK 1.3.1, having entered some text in the editable combo it takes 2 tabs to transfer the selected cell to the next column. With 1.4.2 a single tab while editing the editable combo ends editing and transfers the selection out of the table completely?!?
With these 2 issues I don't know how to make a single tab key reliably transfer to the next cell, between java versions. Can anyone please help me?!??!
(i've attached test code below which can be run in both 1.3 and 1.4 and demonstrates the above behaviour.)
package com.test;
import java.awt.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class TableTest4 extends JFrame {
     private JTable table;
     private DefaultTableModel tableModel;
     public TableTest4() {
          initFrame();
      * Initialises the test frame.
     public void initFrame() {
          // initialise table
          table = new JTable(10, 5);
          tableModel = (DefaultTableModel) table.getModel();
          table.setPreferredScrollableViewportSize(table.getPreferredSize());
          table.setRowHeight(22);
          JScrollPane scrollPane = new JScrollPane(table);
          getContentPane().add(scrollPane);
          JButton dummyBtn1 = new JButton("Dummy Button 1");
          JButton dummyBtn2 = new JButton("Dummy Button 2");
          // initialise frame
          JPanel btnPanel = new JPanel(new GridLayout(2, 1));
          btnPanel.add(dummyBtn1);
          btnPanel.add(dummyBtn2);
          getContentPane().add(btnPanel, BorderLayout.SOUTH);
          // set renderer of first table column to be an editable combobox
          JComboBox editableCombo = new JComboBox();
          editableCombo.setEditable(true);
          TableColumn firstColumn = table.getColumnModel().getColumn(0);
          firstColumn.setCellEditor(new DefaultCellEditor(editableCombo));
     public static void main(String[] args) {
          TableTest4 frame = new TableTest4();
          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);

Run the above code in 1.3 and 1.4 and you can see that after editing a cell, the tab key behaviour works differently between versions.
I don't believe by adding a key listener to the cell editors will have the desired effect.
I've read other posts and from what i've read it looks like the processKeyBinding method of the JTable can be overridden to manually handle key events.
Has anyone done this to handle tab key presses so that the same java app running under 1.3 and 1.4 works in the same way ??? I would really appreciate some advice on this as its very frustrating !

Similar Messages

  • Problem in JTable with a JComboBox cell editor

    Hi gurus,
    Please help! I am having a problem with a JTable that has a JComboBox cell editor. When the table is first loaded, the combo box column displays correct data. But whenever I click the combo box, the selection will be set to the first item in the combo box list once the popup menu pops up even before I make any new selection. It is very annoying.
    Here is how I set the cell editor:
    populateComboBoxModel(); // populate the combo box model.
    DefaultCellEditor cell_editor = new DefaultCellEditor(new JComboBox(
    combo_model));
    contrib_table.getColumnModel().getColumn(1).setCellEditor(
    cell_editor);
    I didn't set the cell renderer so I assume it is using the default cell renderer.
    Thanks !

    Not quite. The example doesn't have a different cell editor for each row of the table. I'm sure I must be missing something, bc I've found many references to the fact that this is possible to do. And I have most of it working. However, when I click on any given combobox, it automatically switches to the first value in the list, not the selected item. I've tried setting the selected item all over the code, but it has no effect on this behavior. Also, it only happens the first time I select a given cell. For example, suppose the first row has items A, B, and C, with B being the selected value. The table initially displays with B in this cell, but when I click on B, it switches to A when it brings up the list. If I select B, and move on to some other cell, and then go back and click on B again, it doesn't switch to A.
    There seems to be a disconnect between the values that I display initially, and the values that I set as selected in the comboboxes. Either that, or it behaves as though I never set the selected item for the combobox at all.
    Any help would be greatly appreciated.

  • Tab Key Navigation in JTable

    Hello All,
    Can anyone please help me with Tab key navigation in a JTable.I
    read all the messages in this group but couldn't implement one.It
    would be a great help if anyone can provide me a working example of how
    to control the tab key in the JTable. I have a JTable with some of the
    columns not editable, I want the focus to be in the first cell and
    whenever the TAB key is pressed, the focus should go to next editable
    cell and select the data in it.For example: if you take a simple table of 4 columns with column 2 not editable, The focus should begin with the first cell(1st column,1st row) and goto (3rd column,1st row) whenever TAB is pressed.It should work in reverse when SHIFT-TAB is pressed.
    I'm new to Java Swing.I would greatly appreciate if anyone can provide me a working example.
    Thanks in advance,
    siddu.

    OK Here is what I have ...
    public class MultipleEditorsPerColumnJTable extends JTable {
    /** Creates a new instance of MultipleEditorsPerColumnJTable */
    public MultipleEditorsPerColumnJTable( int the_column) {
    this.myColumn = the_column;
    this.rowEditors = new ArrayList();
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,int condition, boolean pressed) {
    boolean isSelected = false;
    if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0)) {
    int selRow = getSelectedRow();
    int rowCount = getRowCount();
    int selCol = getSelectedColumn();
    if (selCol == 1) { isSelected= getCellEditor(selRow,selCol).stopCellEditing();}
    int targetRow = (selRow + 1) % rowCount;
    this.editCellAt(targetRow, 1);
    this.getComponentAt(targetRow, 1).requestFocus();
    return super.processKeyBinding(ks,e,condition,pressed);
    I think I know why the requestFocus() is not working. OK, I have a MultipleEditorsPerColumnJTable (sub of JTale), JTextPane, JButton and JLabel. The textpane, label and button have individual editors and renderers. Each time I want to display a new Row, I re-render these components and add it to the table.
    Now with the above code, it still navigates to the next component in the row/ first column in next row depending on the current column. What am I doing wrong?
    Thanks,
    Praveen.

  • Problem sorting JTable with custom cell editor

    Greetings,
    I have created a JTable with a JComboBox as the cell editor for the first column. However, I couldn't simply set the default cell editor for the column to be a JComboBox, since the values within the list were different for each row. So instead, I implemented a custom cell editor that is basically just a hashtable of cell editors that allows you to have a different editor for each row in the table (based on the ideas in the EachRowEditor I've seen in some FAQs - see the code below). I also used a custom table model that is essentially like the JDBCAdapter in the Java examples that populates the table with a query to a database.
    The problem comes when I try to sort the table using the TableSorter and TableMap classes recommended in the Java Tutorials on JTables. All of the static (uneditable) columns in the JTable sort fine, but the custom cell editor column doesn't sort at all. I think that the problem is that the hashtable storing the cell editors never gets re-ordered, but I can't see a simple way to do that (how to know the old row index verses the new row index after a sort). I think that I could implement this manually, if I knew the old/new indexes...
    Here's the code I use to create the JTable:
    // Create the Table Model
    modelCRM = new ContactTableModel();
    // Create the Table Sorter
    sorterCRM = new TableSorter(modelCRM);
    // Create the table
    tblCRM = new JTable(sorterCRM);
    // Add the event listener for the sorter
    sorterCRM.addMouseListenerToHeaderInTable(tblCRM);
    Then, I populate the column for the custom cell editor like this:
    // Add the combo box for editing company
    TableColumn matchColumn = getTable().getColumn("Match");
    RowCellEditor rowEditor = new RowCellEditor();
    // loop through and build the combobox for each row
    for (int i = 0; i < getTable().getRowCount(); i++) {
    JComboBox cb = new JComboBox();
    cb.addItem("New");
    //... code to populate the combo box (removed for clarity)
    rowEditor.add(i,new DefaultCellEditor(cb, i))); //TF
    } // end for
    matchColumn.setCellEditor(rowEditor);
    Any ideas how to do this, or is there a better way to either sort the JTable or use a combobox with different values for each row? Please let me know if more code would help make this clearer...
    Thanks,
    Ted
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    public class RowCellEditor implements TableCellEditor
    protected Hashtable editors;
    protected TableCellEditor editor, defaultEditor;
    public RowCellEditor()
    editors = new Hashtable();
    defaultEditor = new DefaultCellEditor(new JTextField());
    public void add(int row, TableCellEditor editor)
    editors.put(new Integer(row), editor);
    public Component getTableCellEditorComponent(JTable table,
    Object value,
    boolean isSelected,
    int row,
    int column)
    editor = (TableCellEditor) editors.get(new Integer(row));
    if (editor == null)
    editor = defaultEditor;
    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) {
    return true; //TF
    //return editor.isCellEditable(anEvent);
    public void addCellEditorListener(CellEditorListener l) {
    editor.addCellEditorListener(l);
    public void removeCellEditorListener(CellEditorListener l) {
    editor.removeCellEditorListener(l);
    public boolean shouldSelectCell(EventObject anEvent) {
    return editor.shouldSelectCell(anEvent);
    -------------------

    Well, I found a solution in another post
    (see http://forum.java.sun.com/thread.jsp?forum=57&thread=175984&message=953833#955064 for more details).
    Basically, I use the table sorter to translate the row index for the hashtable of my custom cell editors. I did this by adding this method to the sorter:
    // This method is used to get the correct row for the custom cell
    // editor (after the table has been sorted)
    public int translateRow(int sortedRowIndex)
    checkModel();
    return indexes[sortedRowIndex];
    } // end translateRow()
    Then, when I create the custom cell editor, I pass in a reference to the sorter so that when the getTableCellEditorComponent() method is called I can translate the row to the newly sorted row before returning the editor from the hashtable.

  • JComboBox Cell Editor in JTable

    I've scouered the forums for an answer to my question, and while
    finding other valuable advice, I have yet to find an answer to my
    question. But first, a little description:
    I have a JTable consisting of 5 columns:
    col1= standard Object cell editor
    col2= JComboBox cell editor
    col3= JComboBox cell editor, values dependent on col2
    col4= JComboBox cell editor, values dependent on col3
    col5= JComboBox cell editor, values dependent on col4
    Data structure looks like this:
    col1= company object, containing vector of values for col2
    col2= lease object, containing vector of values for col3
    col3= well object, containing vector of values for col4
    col4= pump object, containing vector of values for col5
    col5= simply displayed.
    I have a JButton that adds a new row to the table via dialog, then menu
    options to add entries to the comboboxes/vectors. The kicker here is
    that everything is fine up until I've added a pump, and click the cell
    to view the entry. In my cellEditor class, I have a 'getSelected()'
    method that returns 'combobox.getSelectedIndex()'. When 'edittingStopped()'
    is thrown for any cell in this column, I get a null pointer in my
    getSelectedIndex() method of the lease combobox - only in this pump
    column. Even the part column works correctly. Code snips:
    public class MyApplication ... {
      private TableColumn leaseColumn;
      private TableColumn wellColumn;
      private TableColumn pumpColumn;
      private TableColumn partColumn;
      private LeaseDropDown leaseDropDown;
      private WellDropDown wellDropDown;
      private PumpDropDown pumpDropDown;
      private PartDropDown partDropDown;
      private int currentLease = 0;
      private int currentWell = 0;
      private int currentPump = 0;
      public MyApplication() {
        leaseColumn = pumpshopTable.getColumnModel().getColumn(1);
        leaseDropDown = new LeaseDropDown(companies);
        leaseColumn.setCellEditor(leaseDropDown);
        DefaultTableCellRenderer leaseRenderer =
          new DefaultTableCellRenderer();
        leaseRenderer.setToolTipText("Click for leases");
        leaseColumn.setCellRenderer(leaseRenderer);
        //... same for lease, well, pump, part ...
        leaseDropDown.addCellEditorListener(new CellEditorListener() {
          public void editingCanceled(ChangeEvent e) {
          } // end editingCanceled method
          public void editingStopped(ChangeEvent e) {
            updateCells();
          } // end editingStopped method
        }); // end addCellEditorListener inner class
        //.... same inner class for well, pump, part ...
      } // end MyApplication constructor
      public void updateCells() {
        currentLease = leaseDropDown.getSelectedLease();
        //... get current well, pump, part ...
        leaseDropDown = new LeaseDropDown(companies); // companies=Vector,col1
        leaseColumn.setCellEditor(leaseDropDown);
        //... same for lease, well, pump and part columns ...
      } // end updateCells method
    } // end MyApplication class
    public class LeaseDropDown extends AbstractCellEditor
        implements TableCellEditor {
      private Vector companiesVector;
      private JComboBox leaseList;
      public LeaseDropDown(Vector cVector) {
        companiesVector = cVector;     
      } // end LeaseDropDown constructor
      public Component getTableCellEditorComponent(JTable table,
          Object value, boolean isSelected, int rowIndex, int vColIndex) {
        Company thisCompany = (Company) companiesVector.get(rowIndex);
        Vector leasesVector = (Vector) thisCompany.getLeases();
        leaseList = new JComboBox(leasesVector);
        return leaseList;
      } // end getTableCellEditorComponent method
      public Object getCellEditorValue() {
        return leaseList.getSelectedItem();
      } // end getCellEditorValue method
      public int getSelectedLease() {
        JOptionPane.showInputDialog("Selected lease is: " +
          leaseList.getSelectedIndex());
        return leaseList.getSelectedIndex();          
      } // end getSelectedLease method
    } // end LeaseDropDown class... LeaseDropDown can be extrapolated to well, pump, and part,
    handing well the selected lease, handing pump the selected
    lease and well, handing part the selected lease, well and pump.
    I guess my question is how do I get the selected comboboxitem (I'd
    settle for the entire combobox if there's no other way) to fill in the
    next column? Why does the way I have it now work for the first 2 combobox
    columns and not the third?

    I'll try to provide more details.
    I use a JComboBox implementation as a cell in a JTable. The CombBox is editable . This is what I get when I try to type in something.
    java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1507)
    at java.awt.Component.getLocationOnScreen(Component.java:1481)
    at javax.swing.JPopupMenu.show(JPopupMenu.java:921)
    at javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:177)
    at javax.swing.plaf.basic.BasicComboBoxUI.setPopupVisible(BasicComboBoxUI.java:927)
    at javax.swing.JComboBox.setPopupVisible(JComboBox.java:790)
    at javax.swing.JComboBox.showPopup(JComboBox.java:775)
    I read some related bugs on the sun site but I am not sure if this is a bug and if it is then has it been fixed or work-around provided.
    any insights ??

  • Regarding Tab key Navigation in a page

    Hi,
    I have a requirement regarding the tab key navigation on a page.
    Suppose the focus is on the last field of a page, on clicking the tab key i should go to the first field in the page not the url. i tried using tab index, but the problem is that after coming back to the first field from the last field, on clicking on tab again it does not go on as usual, it suddenly jumps to the url from there.
    Regards
    Krishna

    OK Here is what I have ...
    public class MultipleEditorsPerColumnJTable extends JTable {
    /** Creates a new instance of MultipleEditorsPerColumnJTable */
    public MultipleEditorsPerColumnJTable( int the_column) {
    this.myColumn = the_column;
    this.rowEditors = new ArrayList();
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,int condition, boolean pressed) {
    boolean isSelected = false;
    if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0)) {
    int selRow = getSelectedRow();
    int rowCount = getRowCount();
    int selCol = getSelectedColumn();
    if (selCol == 1) { isSelected= getCellEditor(selRow,selCol).stopCellEditing();}
    int targetRow = (selRow + 1) % rowCount;
    this.editCellAt(targetRow, 1);
    this.getComponentAt(targetRow, 1).requestFocus();
    return super.processKeyBinding(ks,e,condition,pressed);
    I think I know why the requestFocus() is not working. OK, I have a MultipleEditorsPerColumnJTable (sub of JTale), JTextPane, JButton and JLabel. The textpane, label and button have individual editors and renderers. Each time I want to display a new Row, I re-render these components and add it to the table.
    Now with the above code, it still navigates to the next component in the row/ first column in next row depending on the current column. What am I doing wrong?
    Thanks,
    Praveen.

  • Override "crtl + tab" key behaviour with "tab" key for JtextArea .

    I am trying to override the "crtl + tab" key behaviour for JTextArea with "tab" key plus add my own action. I am doing the following.
    1. Setting Tab as forward traversal key for the JTextArea (the default traversal key from JTexArea is "crtl + Tab").
    2. Supplementing the "crtl + Tab" key behaviour with my custom behaviour.
    For the point 2 above, I need to get hold of the Action represented by the "crtl + Tab" key so that I could use that and then follow with my own custom action. But the problem is that there is no InputMap entry for "crtl + tab". I dont know how the "crtl + tab" key Action is mapped for JTextArea. I used the following code to search the InputMap.
                System.out.println("Searching Input Map");
                for (int i = 0; i < 3; i++) {
                    InputMap iMap = comp.getInputMap(i);
                    if (iMap != null) {
                        KeyStroke [] ks = iMap.allKeys();
                        if (ks  != null) {
                            for (int j = 0;j < ks.length ;j++) {
                                System.out.println("Key Stroke: " + ks[j]);
                System.out.println("Searching Parent Input Map");
                for (int i = 0; i < 3; i++) {
                    InputMap iMap = comp.getInputMap(i).getParent();
                    if (iMap != null) {
                        KeyStroke [] ks = iMap.allKeys();
                        if (ks  != null) {
                            for (int j = 0;j < ks.length ;j++) {
                                System.out.println("Key Stroke: " + ks[j]);
                }In short, I need to get the Action associated with the "crtl + tab" for JTextArea.
    regards,
    nirvan.

    There is no Action for Ctrl+TAB. Its a focus traversal key.

  • IECanvas browser + Tab key navigation

    When I embed IE into IECanvas bowser, does it support TAB key navigation?
    If not, How to achieve the same?

    See
    http://www.yourhtmlsource.com/forms/formsaccessibility.html
    Assign the tabindex attribute on the elements you want according to your desired navigation sequence.

  • Problem with tab-key navigation

    I am making chanegs to an existing form.
    I have a tab canvas with 3 tabs, each contains a data block, and other data blocks outside of the tab canvas.
    I wanted the tab key to move the cursor to the next record so I changed the navigation style from "Change Block" to "Change Record", but it did not help. When the cursor is a on a record of a multi-record block and I tab through the items to the last one, pressing the tab key leads me to another tab-page.
    I put in some debug code and noticed that the WHEN-TAB-CHANGED trigger did not fire. The WHEN-VALIDATE-RECORD trigger fired and the cursor block and record number were correct.
    After the tab key took me to another tab-page and I navigated back to the original tab-page. Even though it looks like I'm on the correct tab page, SYSTEM.cursor_block was NOT correct, it was pointing to another data block outside of the tab canvas.
    I checked other forms on our system and I'm pretty sure that changing the navigation style to "Change Record" would work. Perhaps there's something peculiar about this form.
    Any idea will be appreciated.
    Thanks.

    Found the problem.
    For some reason, the WHEN-NEXT-ITEM trigger of the last item of the record is hard-coded to go the another block.

  • JComboBox cell editor *Listener problem

    Hi all,
    I've setup a TreeTable with a JComboBox as a CellEditor for the second column.
    Everything works just fine, except for event handling on a column with a JComboBox as cell editor.
    In my case, the second column of the TreeTable represents the state of the activities. This state can be changed either programmatically or by user input. That is, my application can automatically change the state for some reason, or the user can select a new state for a particular activity with the mouse.
    What I need to achieve is to capture events generated only from the user.
    I've tried different solutions, adding ActionListener or ItemListener to the CellEditor, but they all capture events generated by the application in addition to those generated by the user of the application.
    Can someone please give me some advice in this matter?
    Xserty

    What I need to achieve is to capture events generated only from the user.If you called the JComboBox's dataModel.setSelectedItem method yourself, no event will be fired!Unfortunately, I'm not able to update the dataModel (directly) myself.
    I'm currently using the Creating TreeTables: Part 3; here's how it kinda works: my JTreeTable extends JTable. The JTreeTable has a model: TreeTableModel extends DefaultTreeModel implements InterfaceJTreeTableModel. In this model there are two methods implemented as following:
    public Object getValueAt(Object pParentNode, int pColumn) {
      MutableActivityNode activityNode = (MutableActivityNode) pParentNode;
      try {
        switch (pColumn) {
          case 0 :
            return activityNode.getName();
          case 1 :
            return activityNode.getState();
          case 2 :
            return new Boolean(activityNode.isMonitored());
          default :
            // do something
      } catch (SecurityException se) {
        // do something
      return null;
    public void setValueAt(Object pValue, Object pNode, int pColumn) {
      MutableActivityNode activityNode = (MutableActivityNode) pNode;
      try {
        switch (pColumn) {
          case 1 :
            activityNode.setState((String) pValue);
            break;
          case 2 :
            activityNode.setIsMonitored(((Boolean) pValue).booleanValue());
            break;
          default :
            // do something
      } catch (SecurityException se) {
        // do something
    }Once I create my JTreeTable (with a model), I set the editor of the second column of my JTreeTable to a JComboBoxCellEditor.
    As you may have noticed, all the information are stored in the node of the TreeTableModel and the information is displayed and set by the two methods above.
    Thank you anyways for the advice :))
    Have you any idea on how I could solve the problem in this case?
    Xserty

  • JTable TAB key listener

    Hi all:
    I'm trying to write a filterable jtable. User can input the filter rule in the table header and the table displays the filtered data at the same time when the user inputs letters. The table filter works fine. But when I try to add "TAB" key listener, I find that I can't track the "TAB" key. I use a customerized cell renderer to display the filterable table header, a customerized cell editor to edit the filterable table header. The cell editor is created like this:
    JTextField textField = new JTextField("");
    DefaultCellEditor cellEditor = new DefaultCellEditor(textField);
    And I add a KeyListener to the textField. The KeyListener can track other keys like "Shift", "Alt", "Ctrl", but it can't track "TAB". It's weird. I also add the KeyListener to JTableHeader, JTable, but when I edit something in the JTextField, I still can't catch the "TAB" key. Have any ideas? Thank you for your time.

    by default the Tab is used (and consumed) by
    focusManager to move focus between components. If you
    want to get it in a component you have to signal the
    manager to keep it's hands off. How to do so depends
    on the jdk version. Focus handling changed
    considerably between 1.3 and 1.4: Prior to 1.4 you
    have to subclass the component in question to return
    true on isManagingFocus(), since 1.4 you have to set
    the comp's focusTraversalKeys to make the manager take
    those instead of the default keys.
    Greetings
    JeanetteThanks Jeanette, it works. I use the Component.setFocusTraversalKeysEnabled(false) to disable all traversal keys of JTextField and add a KeyEventDispatcher to the KeyboardFocusManager. It finally works. Users can use "TAB" keyStroke and "Shift-TAB" keyStroke to traverse in the filterable table header now. Thank you for your great help and the $$ are yours.

  • Editable JCombobox cell editor length limit

    Hi All,
    I have an editable JCombobox as a celleditor to one of the column in JTable, How do I limit the characters in the cell editor?
    Thanks

    A JComboBox uses a JTextField as it's cell editor. You should read up on how you would do this for a normal JTextField by using a custom Document:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
    Here's an example using JComboBox. I haven't tried it in a JTable but I assume it should work.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.plaf.basic.*;
    public class ComboBoxNumericEditor extends BasicComboBoxEditor
         public ComboBoxNumericEditor(JComboBox box)
              editor.setDocument( new NumericListDocument(box.getModel()) );
         public static void main(String[] args)
              String[] items = { "one", "two", "three", "four" };
              JComboBox list = new JComboBox( items );
              list.setEditable( true );
              list.setEditor( new ComboBoxNumericEditor( list ) );
              JFrame frame = new JFrame();
              frame.getContentPane().add( list );
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
         class NumericListDocument extends PlainDocument
              ListModel model;
              public NumericListDocument(ListModel model)
                   this.model = model;
              public void insertString(int offset, String text, AttributeSet a)
                   throws BadLocationException
                   //  Accept all entries in the ListModel
                   for (int i = 0; i < model.getSize(); i++)
                        Object item = model.getElementAt(i);
                        if (text.equals( item.toString() ))
                             super.insertString(offset, text, a);
                             return;
                   //  Build the new text string assuming the insert is successfull
                   String oldText = getText(0, getLength());
                   String newText =
                        oldText.substring(0, offset) + text + oldText.substring(offset);
                   //  Edit the length of the new string
                   if (newText.length() > 2)
                        Toolkit.getDefaultToolkit().beep();
                        return;
                   //  Only numeric characters are allowed in the new string
                   //  (appending the "0" will allow an empty string to be valid)
                   try
                        Integer.parseInt(newText + "0");
                        super.insertString(offset, text, a);
                   catch (NumberFormatException e)
                        Toolkit.getDefaultToolkit().beep();
    }

  • TAB key for lyrics in score editor not working anymore!

    I have been editing music for score printing in LOGIC for ever. Suddenly the TAB key won't take me to the next note, but finishes the inputting. I never get beyond the first syllable! I have even disabled the key command for TAB in other editors to make sure they don't clash - but no change. Can anyone help?
    Christoph

    Have you tried without memory card to se if same result in case of possible corruption?
    Suggest that you backup essential data with Nokia Suite and return device to "Out of box" state by keying in *#7370# followed by 12345 (default Nokia lock code unless altered by user).
    Happy to have helped forum in a small way with a Support Ratio = 37.0

  • ItemFocusOut not catching  "TAB" key in Datagrid edited cell?

    In DataGrid, "keyUp" can catch "TAB" key when it is pressed,
    but the Keyboard event has less information needed. I tried
    itemFocusOut, but it seems DataGridEvent would not catch it. Any
    tips on how to make "TAB" key generate DataGridEvent or similar
    event?
    Platforms with this issue: WIN-XP/JDK-1.6/Air-1.5/FLEX
    SDK-3.2
    Thanks!
    -Herbert

    Let me rephrase like this:
    In our application, a DataGrid’s edited cell has
    “itemEditEnd” and “itemEditBeginning”
    handlers defined. However when a “TAB” key is pressed
    to navigate from one editable cell to another editable cell, none
    of the above handlers can catch this special key stroke event.
    Our intention is to make “TAB” key to emit an
    event that can be caught by above handlers. Or, in other words, we
    would like make “TAB” key to be similar(in the sense of
    generating events) to that of “Enter” key when pressed.

  • PJC tab-key navigation problem within bean  (FORMS intercepting tab key??)

    Using Forms 10.1.2.3, IE7, JRE 1.6
    When attempting to navigate within the bean area, it appears as if FORMS is suppressing the keyEvent when the tab key is pressed. This means that I cannot use tab or shift-tab to navigate within the PJC's editable fields/buttons. I can click on them, enter data within them, but tab is somehow intercepted. When I place my PJC within a normal (non-forms) Java window, everything works fine.
    Documentation that I've read seems to indicate that tab should navigate perfectly fine within the bean area.
    Any ideas?

    Hi,
    This is how I did it. Sorry about the formatting, it was OK when I pasted the code fragment in.
    My class contains this in the variable definitions.
    private AWTEventListener keyListener = new DoKey ();
    private class DoKey implements AWTEventListener {
    public void eventDispatched (AWTEvent e) {
    //System.err.println("eventDispatched " + e.toString());
    //System.err.println("eventDispatched source " + e.getSource().toString());
    if ((e instanceof KeyEvent) && (e.getSource() instanceof Component)) {
    * The event was a key pressed event and it was sourced from a Component.
    KeyEvent evt = (KeyEvent) e;
    if (evt.getID() == evt.KEY_PRESSED) {
    if (evt.getKeyCode() == evt.VK_TAB) {
    if (evt.isShiftDown()) {
    ((Component)e.getSource()).transferFocusBackward();
    else {
    ((Component)e.getSource()).transferFocus();
    The listener is enabled when on initialisation
    Toolkit.getDefaultToolkit().addAWTEventListener (keyListener, AWTEvent.KEY_EVENT_MASK);
    Regards, Tony C

Maybe you are looking for

  • Trial wont work because of old one

    I used a 30 day trial for Photoshop a couple months back, now when I try to use it with Cloud it tells me that my trial is over, what do u do?

  • Safari 7.0.6 crashes on os 10.9.4...

    Hey, I need a little help. This is the log report I guess, I've been searching and search for help, but nothing has worked... Process:         Safari [1628] Path:            /Applications/Safari.app/Contents/MacOS/Safari Identifier:      com.apple.Sa

  • What type of questions can i expect for master data?

    hi, am preparing for the interview. pls... let me know those questions for master data. thanks to all

  • Relink audio in imovie?

    There seem to be a number of questions here pertaining to this or similar topics, but no answers . . I made a copy of an iMovie project in order to create a different version of it the movie. The original project includes an audio track which had bee

  • PI post processing - configure the role of Integration service fails

    I am running post processing template, and it keeps failing. So I have a couple questions: Can I rerun the PI template multiple times until the entire process completes successfully? Must every process complete successfully? I have 100% but it is red