FocusLost in a CellEditor

I am using a cell editor that either uses (1)a jpanel - comprising of several textfields and a button; (2) a textfield; and (3) another jpanel - comprising of several comboboxes and a textfield. Note that the value of each cell has a header that determines which "type" of editor will be used. I am having problems creating validation for the first panel. I want to display a message whenever the textfields in a specific row are filled up and if its button is not clicked. I added a focus listener to each element in the panel and it works. But whenever i try to choose the same textfield but in a different row, validation won't run (since there is no focus gained since it is the same component). Can you tell me any suggestions that may make this validation work?

Just to clarify, the panel consists of 3 textfields (lastname, firstname, middlename) and one button (search). The value for each cell
in this particular column (that uses the said editor) is a string that has the format of:
<TYPE0><DELIM><LASTNAME><DELIM><FIRSTNAME><DELIM><MIDDLENAME>
Note that type0 refers to panel1, type1 to txtfield, and type2 to panel2
Delim is "/t"
lastname is textfield1 from panel1, etc.
So every time i click the search button, the string value for the specific cell changes.

Similar Messages

  • FocusLost event for JTextField sometimes triggered, sometimes not

    Some background.
    A column in a table consists of a number of cells.
    Each cell can be a JTextField or a JComboBox.
    I have written a CellEditor who returns either a JTextField or a JComboBox depending on some conditions.
    The JTextField listens for a FocusLost event to update the database.
    When I leave the first cell the FocusLost event is always triggered.
    For the ther cells the FocusLost event is triggeed every now and then.
    In the mean time I have found a simple workaround by placing the update code in method getCellEditorValue() which is called always by the table when moving to the next cell.
    I am just curious if someone has an explanation for this inconsistent behaviour of the FocusLost event.
    Code is below:
    * QuoteProductPropertyValueEditor.java
    * Created on May 4, 2005
    package tsquote.gui;
    * @author johnz
    import java.awt.Component;
    import java.util.EventObject;
    import java.awt.event.*;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import tsquote.controller.QueryHandler;
    import tsquote.exception.FinderException;
    import tsquote.gui.control.GenericTableModel;
    import tsquote.gui.control.Table;
    import tsquote.util.Messager;
    public class QuoteProductPropertyValueEditor implements TableCellEditor {
          * We use EvetListenerList, because it is thread-safe
         protected EventListenerList listenerList = new EventListenerList();
         protected ChangeEvent changeEvent = new ChangeEvent(this);
         private List<Component> componentList = new ArrayList();
         private Map<Integer, Integer> indexMap = new HashMap(); // maps row to index
         private Table table;
         private int currentRow;
         private QueryHandler queryHandler = QueryHandler.getInstance();
         public QuoteProductPropertyValueEditor() {
              super();
         public Object getCellEditorValue() {
              Component component = componentList.get(indexMap.get(currentRow));
              if (component instanceof JComboBox) {
                   JComboBox comboBox = (JComboBox) component;
                   return comboBox.getSelectedItem();
              JTextField textField = (JTextField) component;
              return textField.getText();
         public Component getTableCellEditorComponent(
                   JTable jTable,
                   Object value,
                   boolean isSelected,
                   int row,
                   int column) {
              final int thisRow = row;
              System.out.println("getTableCellEditorComponent(): thisRow=" + thisRow);
              table = (Table) jTable;
              currentRow = thisRow;
              if (!indexMap.containsKey(thisRow)) {
                   System.out.println("Control added: thisRow=" + thisRow);
                   indexMap.put(thisRow, componentList.size());
                   // This is actually a tsquote.gui.control.Table
                   GenericTableModel genericTableModel = table.getGenericTableModel();
                   List<Map> list = genericTableModel.getList();
                   Map recordMap = list.get(thisRow);
                   Boolean hasList = (Boolean) recordMap.get("product_property.has_list");
                   if (hasList) {
                        JComboBox comboBox = new JComboBox();
                        componentList.add(comboBox);
                        comboBox.addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent event) {
                                  fireEditingStopped();
                        for (int i=0; i<=row +1; i++) {
                             comboBox.addItem("Item" + i);
                   } else {
                        JTextField textField = new JTextField();
                        componentList.add(textField);
                        textField.addFocusListener(new FocusAdapter() {
                             public void focusLost(FocusEvent e) {
                                  System.out.println("textField: thisRow=" + thisRow);
                                  JTextField textField = (JTextField) componentList.get(indexMap.get(thisRow));
                                  String newValue = textField.getText();
                                  fireEditingStopped();
                                  updateQuoteProductProperty(thisRow, newValue);
                        String text = (String) recordMap.get("quote_product_property.value");
                        textField.setText(text);
              Component component = componentList.get(indexMap.get(thisRow));
              if (component instanceof JComboBox) {
                   JComboBox comboBox = (JComboBox) component;
                   if (value == null) {
                        comboBox.setSelectedIndex(0);
                   } else {
                        comboBox.setSelectedItem(value);
              } else {
                   JTextField textField = (JTextField) component;
                   textField.setText((String) value);
              return component;
         private void updateQuoteProductProperty(
                   int row,
                   String newValue) {
              // Get PK quote_prodcut_property from list
              GenericTableModel genericTableModel = table.getGenericTableModel();
              List<Map> list = genericTableModel.getList();
              Map modelRecordMap = list.get(row);
              String storedValue = (String) modelRecordMap.get("quote_product_property.value");
              // If nothing changed, ready
    //          if (storedValue == null) {
    //               if (newValue == null) {
    //                    return;
    //          } else {
    //               if (storedValue.equals(newValue)){
    //                    return;
              // Update model
              modelRecordMap.put ("quote_product_property.value", newValue);
              Integer quoteProductPropertyID = (Integer) modelRecordMap.get("quote_product_property.quote_product_property_id");
              try {
                   queryHandler.setTable("quote_product_property");
                   queryHandler.setWhere("quote_product_property_id=?", quoteProductPropertyID);
                   Map recordMap = queryHandler.getMap();
                   recordMap.put("value", newValue);
                   recordMap.get("quote_product_property.value");
                   queryHandler.updateRecord("quote_product_property", "quote_product_property_id", recordMap);
              } catch (FinderException fE) {
                   Messager.warning("Cannot find record in quote_product_property\n" + fE.getMessage());
         public void addCellEditorListener(CellEditorListener listener) {
              listenerList.add(CellEditorListener.class, listener);
         public void removeCellEditorListener(CellEditorListener listener) {
              listenerList.remove(CellEditorListener.class, listener);
         public void cancelCellEditing() {
              fireEditingCanceled();
         public boolean stopCellEditing() {
              fireEditingStopped();
              return true;
         public boolean isCellEditable(EventObject event) {
              return true;
         public boolean shouldSelectCell(EventObject event) {
              return true;
         protected void fireEditingStopped() {
              CellEditorListener listener;
              Object[] listeners = listenerList.getListenerList();
              for (int i = 0; i < listeners.length; i++) {
                   if (listeners[i] == CellEditorListener.class) {
                        listener = (CellEditorListener) listeners[i + 1];
                        listener.editingStopped(changeEvent);
         protected void fireEditingCanceled() {
              CellEditorListener listener;
              Object[] listeners = listenerList.getListenerList();
              for (int i = 0; i < listeners.length; i++) {
                   if (listeners[i] == CellEditorListener.class) {
                        listener = (CellEditorListener) listeners[i + 1];
                        listener.editingCanceled(changeEvent);
    }

    The JTextField listens for a FocusLost event to update the database.I don't recommend using a FocusListener. Wouldn't you get a FocusLost event even if the user cancels any changes made to the cell?
    Whenver I want to know if data has changed in the table I use a TableModelListener:
    http://forum.java.sun.com/thread.jspa?threadID=527578&messageID=2533071
    I'm not very good at writing cell editors so I don't. I just override the getCellEditor method to return an appropriate editor. Here's a simple example:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableComboBoxByRow extends JFrame
         ArrayList editors = new ArrayList(3);
         public TableComboBoxByRow()
              // Create the editors to be used for each row
              String[] items1 = { "Red", "Blue", "Green" };
              JComboBox comboBox1 = new JComboBox( items1 );
              DefaultCellEditor dce1 = new DefaultCellEditor( comboBox1 );
              editors.add( dce1 );
              String[] items2 = { "Circle", "Square", "Triangle" };
              JComboBox comboBox2 = new JComboBox( items2 );
              DefaultCellEditor dce2 = new DefaultCellEditor( comboBox2 );
              editors.add( dce2 );
              String[] items3 = { "Apple", "Orange", "Banana" };
              JComboBox comboBox3 = new JComboBox( items3 );
              DefaultCellEditor dce3 = new DefaultCellEditor( comboBox3 );
              editors.add( dce3 );
              //  Create the table with default data
              Object[][] data =
                   {"Color", "Red"},
                   {"Shape", "Square"},
                   {"Fruit", "Banana"},
                   {"Plain", "Text"}
              String[] columnNames = {"Type","Value"};
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              JTable table = new JTable(model)
                   //  Determine editor to be used by row
                   public TableCellEditor getCellEditor(int row, int column)
                        int modelColumn = convertColumnIndexToModel( column );
                        if (modelColumn == 1 && row < 3)
                             return (TableCellEditor)editors.get(row);
                        else
                             return super.getCellEditor(row, column);
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              TableComboBoxByRow frame = new TableComboBoxByRow();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

  • JTextField.focusLost is called multiple times. Why?

    I have a JTextField component called projectNum.
    On focusLost I'm trying to prevent user to leave an empty field.
    But I have a problem, because focusLost is called two times.
    Here is a code snippet:
    projectNum.addFocusListener(new FocusAdapter() {
                   public void focusGained(FocusEvent e) {}
                   public void focusLost(java.awt.event.FocusEvent e) {
                        if(!e.isTemporary()){ //only for permanent lost of focus          
                             if (validProjectNum()){
    newProject.setProjectNum(Integer.valueOf(projectNum.getText().trim()).intValue());
                           }else{
                                if(!projectNum.hasFocus()){
                                     projectNum.requestFocus();
              });Method "validProjectNum()" simply checks if JTextField is empty and
    if so, shows JOptionPane message and returns false.
    Problem is that I'm geting that message twice
    (four times if I exclude: if(!e.isTemporary()) ).
    I can't figure out who is calling focusLost the second time.
    How can I prevent it to be called only once.
    I appreciate any help or hint.
    Thanks.

    OK, but where to show a message to a user?if the textfield is empty, this line executes
    if(tf.getText().equals("")) return false;
    perhaps you could add your message as part of the
    'block' of this if statementWell, I've tried that allready (see my second post, method validProjectNum()
    does exactly that).
    Anyway, I solved the problem using focusLost and a little trick:jTextField.requestFocus();                
           jTextField.setFocusable(false);          
           JOptionPane.showMessageDialog(null, "error message");
           jTextField.setFocusable(true);  
           jTextField.requestFocus();        So as you can see, key thing is to temporary disable focus on component
    and than enable it back after JOptionPane.showMessageDialog().
    It looks like JOptionPane.showMessageDialog()
    triggers focusLost() event.
    Thanks everyone.

  • Question about How to Use Custom CellEditors

    Hi:
    I have been trying to implement something like this: I have a JPanel, and when you double-click a particular spot on it, I want a textbox to appear. Currently, I am implementing it by using an undecorated JDialog that contains a JTextField in it (such that the text field occupies all the space in the dialog, i.e. you can't even tell that there is a dialog). This seems like a hack to me.
    Another alternative that I have been thinking about is using layered panes, and hiding the textfield below the jpanel, and only bringing it to the front when the user double-clicks.
    Then, I stumbled onto custom celleditors. Now, it seems that everyone is using them in JTables, JLists, JComboBoxes, etc. and I was wondering if it is something that I can use with a JPanel.
    Can anyone comment on the implementations I am considering, as well as using custom celleditors with a JPanel?
    Thanks in advance,
    LordKelvan

    Still don't understand your requirement. Does the text field stay there or disappear after the data is entered? If it disappears, then how do you change the value, do you have to click on the exact same pixel again?
    Maybe you could use a MouseListener and then display a JOptionPane or JDialog to prompt for the information. Or if you want to display a JTextField then add a JTextField to the panel and then when the user enters the data by using the enter key or by clicking elsewhere on the GUI you remove the text field from the panel.

  • Help - Focuslost is trigered too many time during jtextfield validation.

    Hi all,
    I am designing a form containing multiple fields with field validations.
    The program supposes bring the focus back to that particular field after the error message is displayed. However; the
    error/warning message is displayed infinitely between the two focusLost events of the two Jtextfields when the focus is switched between the two jtextfields. I tried to google it, but there was no success.
    Can anyone tell me why?
    Thanks a lot.
    core code
        private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {                                     
            // TODO add your handling code here:evt.getSource();
            JTextField roomTag=(JTextField) evt.getSource();
             String text = roomTag.getText();
             if (text.length() >= 3) {
                try {
                        Integer.parseInt(text);
                } catch(NumberFormatException nfe) {
                 //    Toolkit.getDefaultToolkit().beep();
    //SwingUtilities.invokeLater(new FocusGrabber(this.jTextField1));
                   JOptionPane.showMessageDialog(null, "It must be a numeric value");
                   //roomTag.requestFocus();
                   jTextField1.requestFocus();
                   //return;
             } else {
                   JOptionPane.showMessageDialog(null, "It must be 3 chars at least");
                   //roomTag.requestFocus();
                    jTextField1.requestFocus();
                    //return;
        private void txtPhoneFocusLost(java.awt.event.FocusEvent evt) {                                  
            // TODO add your handling code here:
            JTextField roomTag=(JTextField) evt.getSource();
             String text = roomTag.getText();
             if (text.length() <= 12) {
                try {
                    Long a=Long.parseLong(text);
                } catch(NumberFormatException nfe) {
                   JOptionPane.showMessageDialog(null, "The phone number must be a numeric value");
                   txtPhone.requestFocus();
                   //roomTag.requestFocus();
                   //jTextField1.requestFocus();
                   //return;
             } else {
                   JOptionPane.showMessageDialog(null, "The phone number must be 12 chars at most");
                    txtPhone.requestFocus();
                   //roomTag.requestFocus();
                    //jTextField1.requestFocus();
                    //return;
                                         Edited by: ehope on Nov 1, 2009 5:14 PM
    Edited by: ehope on Nov 1, 2009 5:18 PM
    Edited by: ehope on Nov 1, 2009 5:21 PM

    A search of the forum on two terms -- focusLost multiple -- came up with some interesting hits: [forum search|http://search.sun.com/main/index.jsp?all=focuslost+multiple&exact=&oneof=&without=&nh=10&rf=0&since=&dedupe=true&doctype=&reslang=en&type=advanced&optstat=true&col=main-all]
    including a bug report and a work-around by camickr.
    Another possible work around is to remove the focuslistener, then re-add it at the end of the focuslistener but via a Swing Timer to delay its re-addition.

  • Breaking a focuslost event in validating a JTextfield

    This problem seems to occur often but I have not found a solution. A JTextfield gets its content validated (for example the field must not be blank) when the focus on the field is lost, and retains the focus until the user enters valid data, after which the focus moves to another field. But say the user decides not to proceed with the input and just decides to click a Close or Exit JButton and come back later. Of course each click of the Close button triggers the focuslost validation on the textfield, making it programatically impossible to quit the frame normally. How does one break the focus on the textfield and exit gracefully?

    Yes, that works. In the jtextfieldFieldFocusLost method i included:
    String jcomponent = evt.getOppositeComponent().getClass().getName();
           if (jcomponent.equals("javax.swing.JTextField"))
              ..do the validation
           else
             ..let the Quit button close the form
           }Great answer, many thanks.

  • Order of focusLost and actionPerformed events in Swing on Red Hat

    Hi!
    I have quite complicated bug, which must be fixed as soon as possible. Currently I am drinking my fifth coffee and I cannot find anything about this bug on the net.
    The bug looks like that:
    I have pane with several JTextField on it and a Save Button.
    Each JTextField has FocusListener with focusLost method. On focusLost event the entered text is validated and moved to the model object.
    After pressing the Save Button model object is saved to DB. This work perfect on Windows but not on Red Hat ( I have not yet check on Solaris).
    I enter the text in text field and press the save button with mouse. Then I receive information that the actionPerformed is called and save model object without entered text. After saving the focusLost is invoked and move the entered text to the previous saved object.
    I have look into several books but I haven't find any information about order of events. Maybe if I took some more time, but project dead line is soon.
    This is not my application, I only maintain it. I cannot read the JTextField on actionPerformed due to validation of data.
    Have someone any experience with such problem?
    I will be very appreciated for any help.

    I haven't receive any reply yet, but maybe my workaround will help someone else.
    I have figured out, that if I implement actionPerformed as InvokeLater it will cause proper order of focusLost and actionPerformed.
    So it looks like:
    actionPerformed() {
      SwingInvoke.invokeLater(new Runnable() {
        createSaveThread()
        startSaveTread()
    }Have a nice day :)

  • FocusLost of jtable is not triggered when focus is lost from a cell editor.

    Hi
    I have a jtable and some columns in the table contains editable cells. I started editing a cell and, before the cell editing is stopped, i clicked another component in the panel using mouse. At that time, the focusLost() method of the table is not triggered. So that the code written in my focusLost() method of table is not working.
    If I add focuslistener to the cell editors, the focusLost() method of this cell editors are triggered at that time.
    Shall I need to add focuslistener to each cell editors used in my jtable ? Anybody know a better solution to handle this problem ?
    Regards
    Anoop

    Add this to your code.
    yourTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

  • How to use a JTextField as CellEditor and Renderer in JTable

    Hi, I want to use a JTextField as a CellEditor and CellRenderer in an JTable. How can I do this?
    Thanks for your help.

    For using JTextField as a CellEditor in JTable...try as directed below:
    TableColumnModel tcm = table.getColumnModel();
    JTextField txt = new JTextField();
    /***now specify the column number in which u want to add this textfield, e.g in the example below iam adding this textfield to 1st column***/
    tcm.getColumn(0).setCellEditor(new DefaultCellEditor(qty));
    Rajat.

  • Paste inside JTable CellEditor

    I have a JTable in which I've implemented a TextArea CellEditor. In this component, I've caught the Ctrl-V KeyEvent and have called a paste method accordingly. Also in the table I've caught the same event and called the same paste method. The problem is when I double click on the cell (editor is available now) my paste method gets called and then the default windows (i'm guessing) paste functionality also kicks in. So the cell gets overwritten, and my data (which I had considerably formatted) is lost. Is there any way I can stop this from happening??

    JTable has a default Action for the Ctrl+V KeyStroke. You should replace this default with your Action. Here is an [url http://forum.java.sun.com/thread.jsp?forum=57&thread=509913]example of how you can replace/remove an Action.

  • Two elements in Table CellEditor

    Whether it is possible in the table (CellEditor) to insert a sheaf of elements? For example Caption and TextEdit? It is necessary for a news line. Can there is other way of visualization. I shall be glad to your offers!

    If you only want to display news, you can use a context node "NewsItems" with attributes "HeaderText", "Text" etc. and write code like the following in method wdDoModifyView() to rebuild the view after a change of the data:
    boolean newsChanged= ...;
    if (newsChanged)
      IWDUIElementContainer panel = (IWDUIElementContainer) view.getElement("NewsPanel");
      panel.destroyAllChildren();
      for (int i = 0; i < wdContext.nodeNewsItems().size(); ++i)
        INewsItemsElement item = wdContext.nodeNewsItems().getNewsItemsElementAt(i);
        IWDCaption header = (IWDCaption) view.createElement(IWDCaption.class, null);
        header.setText(item.getHeaderText());
        panel.addChild(item);
        IWDTextView content = (IWDTextView) view.createElement(IWDTextView.class, null);
        content.setText(item.getText());
        panel.addChild(content);
    I omitted the code for the layout and layout data, but you should get the idea.
    Armin

  • JTable CellEditor does not reflect UI changes

    When I change the application font size vi a UIManager property change and call updateComponentTreeUI the font changes for everything but my JTable CellEditors. Anybody have a suggested solution.
    thanks

    The font change property is set with a customizer and propagated to the entire app via updateComponentTreeUI. If I don't call updateComponentTreeUI I will not see the font change. Calling updateComponentTreeUI is the standard way to propagate property changes. It just doesn't seem to work for TableCellEditors. I need to do something in addition to updateComponentTreeUI so the TableCellEditors will reflect the font customization.
    Steve

  • JComboBox focusLost sets Transaction dirty

    A JComboBox bound to a ViewObject in an ApplicationModule sets that ApplicationModule's transaction dirty even if no changes were made. The combobox list wasn't even opened, just focus in and out or tab-in and tab-out.
    This seems to be a side-effect of having a different column displayed to that bound to the JComboBox.
    This binding works correctly (VcVehicleRegistration is the bound column and the displayed column):
    mVcVehicleRegistration.setModel(JUComboBoxBinding.createLovBinding(panelBinding, mVcVehicleRegistration, "VehicleIncidents", null, "VehicleIncidentsIter", new String[] {"VcVehicleRegistration"}, "VehicleView", new String[] {"VcVehicleRegistration"}, new String[] {"VcVehicleRegistration"}, null, null));
    whereas this fails (VcCauseCode is the bound column, but VcDescription is displayed):
    mVcCauseCode.setModel(JUComboBoxBinding.createLovBinding(panelBinding, mVcCauseCode, "VehicleIncidents", null, "VehicleIncidentsIter", new String[] {"VcCauseCode"}, "CauseView", new String[] {"VcCauseCode"}, new String[] {"VcDescription"}, null, null));
    Tony.

    I'm doing more-or-less what you did.
    I've just reproduced it with a simple panel.
    Panel already exists with 5 attributes from a single ViewOject (which are from a single EntityObject) - PersonnelView.
    This operates fine and tabbing-through has no problems.
    Drop in a ComboBox and bind it to the Branch ViewObject (also single Entity) and display the Branch name:
    jComboBox1.setModel(JUComboBoxBinding.createLovBinding(panelBinding, jComboBox1, "PersonnelView", null, "PersonnelViewIter", new String[] {"VcBranch"}, "BranchView", new String[] {"VcBranch"}, new String[] {"VcBranchName"}, null, null));
    Tabbing out of this field sets transaction dirty.
    How can I check I really am using C:\JDeveloper\BC4J\jlib\FixForBug2632152.jar?
    I can e-mail the relevant SQL, BusinessComponents XML and JClient.java if you like.
    In the mean-time, I've sub-classed JUNavigationBar and dumped the stack when transactionStateChanged() is called (see below).
    Tony.
    java.lang.Exception: Stack trace
         void java.lang.Thread.dumpStack()
              Thread.java:997
         void com.lynx.cc.NavBar.transactionStateChanged(boolean)
              NavBar.java:106
         void oracle.jbo.uicli.binding.JUApplication.setTransactionModified()
              JUApplication.java:860
         void oracle.jbo.uicli.jui.JUPanelBinding.callBeforeSetAttribute(oracle.jbo.uicli.binding.JUControlBinding, oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object)
              JUPanelBinding.java:481
         void oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object, boolean)
              JUCtrlValueBinding.java:466
         void oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object)
              JUCtrlValueBinding.java:422
         void oracle.jbo.uicli.binding.JUCtrlListBinding.setTargetAttrsFromLovRow(oracle.jbo.Row, oracle.jbo.Row)
              JUCtrlListBinding.java:678
         void oracle.jbo.uicli.binding.JUCtrlListBinding.updateTargetFromSelectedValue(java.lang.Object)
              JUCtrlListBinding.java:748
         void oracle.jbo.uicli.jui.JUComboBoxBinding.actionPerformed(java.awt.event.ActionEvent)
              JUComboBoxBinding.java:430
         void javax.swing.JComboBox.fireActionEvent()
              JComboBox.java:870
         void javax.swing.JComboBox.selectedItemChanged()
              JComboBox.java:894
         void javax.swing.JComboBox.contentsChanged(javax.swing.event.ListDataEvent)
              JComboBox.java:950
         void javax.swing.AbstractListModel.fireContentsChanged(java.lang.Object, int, int)
              AbstractListModel.java:79
         void javax.swing.DefaultComboBoxModel.setSelectedItem(java.lang.Object)
              DefaultComboBoxModel.java:86
         void javax.swing.JComboBox.actionPerformed(java.awt.event.ActionEvent)
              JComboBox.java:925
         void javax.swing.plaf.basic.BasicComboBoxUI$EditorFocusListener.focusLost(java.awt.event.FocusEvent)
              BasicComboBoxUI.java:1399
         void java.awt.AWTEventMulticaster.focusLost(java.awt.event.FocusEvent)
              AWTEventMulticaster.java:171
         void java.awt.Component.processFocusEvent(java.awt.event.FocusEvent)
              Component.java:3642
         void javax.swing.JComponent.processFocusEvent(java.awt.event.FocusEvent)
              JComponent.java:1980
         void java.awt.Component.processEvent(java.awt.AWTEvent)
              Component.java:3535
         void java.awt.Container.processEvent(java.awt.AWTEvent)
              Container.java:1164
         void java.awt.Component.dispatchEventImpl(java.awt.AWTEvent)
              Component.java:2593
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1213
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         boolean java.awt.LightweightDispatcher.setFocusRequest(java.awt.Component)
              Container.java:2076
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1335
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Component.requestFocus()
              Component.java:4174
         void javax.swing.JComponent.grabFocus()
              JComponent.java:915
         void javax.swing.DefaultFocusManager.focusNextComponent(java.awt.Component)
              DefaultFocusManager.java:93
         void javax.swing.DefaultFocusManager.processKeyEvent(java.awt.Component, java.awt.event.KeyEvent)
              DefaultFocusManager.java:71
         void javax.swing.JComponent.processKeyEvent(java.awt.event.KeyEvent)
              JComponent.java:2007
         void java.awt.Component.processEvent(java.awt.AWTEvent)
              Component.java:3553
         void java.awt.Container.processEvent(java.awt.AWTEvent)
              Container.java:1164
         void java.awt.Component.dispatchEventImpl(java.awt.AWTEvent)
              Component.java:2593
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1213
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         boolean java.awt.LightweightDispatcher.processKeyEvent(java.awt.event.KeyEvent)
              Container.java:2155
         boolean java.awt.LightweightDispatcher.dispatchEvent(java.awt.AWTEvent)
              Container.java:2135
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1200
         void java.awt.Window.dispatchEventImpl(java.awt.AWTEvent)
              Window.java:926
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         void java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent)
              EventQueue.java:339
         boolean java.awt.EventDispatchThread.pumpOneEventForHierarchy(java.awt.Component)
              EventDispatchThread.java:131
         void java.awt.EventDispatchThread.pumpEventsForHierarchy(java.awt.Conditional, java.awt.Component)
              EventDispatchThread.java:98
         void java.awt.EventDispatchThread.pumpEvents(java.awt.Conditional)
              EventDispatchThread.java:93
         void java.awt.EventDispatchThread.run()
              EventDispatchThread.java:85

  • Clear selection on FocusLost of Jtable.

    Hi
    I have a jtable in which some columns are editable and some are non-editable. I want to clear the selections in jtbale when focus is lost from jtable.
    But i cannot write the code table.clearSelection() in the focusLost() method of JTable since it will not be invoked when another component is clicked using mouse, when the table editing is started.
    When another component is clicked when the table is in edit mode, the focusLost() of Jtable will not be invoked, but the focusLost() of that editor component will be triggered. So that table.clearSelection() will not work in this case.
    Can anybody suggest a solution to this problem ? I have already added putClienProperty("terminateEditOnFocusLost", Boolean.TRUE) to stop cell editing when focus is lost. Is there any methods like table.putClientProperty("clearSelectionOnFocusLost", Boolean.TRUE); ?? Do i need to add focus listener to each editor components ? Please hep.
    with thanks & regards
    Anoop

    You can listen for all focus change events using the following code:
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
         .addPropertyChangeListener("focusOwner", new PropertyChangeListener()
         public void propertyChange(PropertyChangeEvent e)
              if (e.getNewValue() == null) return;
              Component c = (Component)e.getNewValue();
              System.out.println();
              System.out.println(c.getClass());
              System.out.println(c.getParent().getClass());
    });When your table gains focus you can set a boolean variable to indicate this. When another component gains focus (whose parent isn't the table), then you clear the table selection and reset the boolean variable.

  • FocusLost event for JTable during cell editing

    When a cell in a JTable is getting edited, how can I get notified of the focusLost event? I added the focus listener using JTable.addFocusListener, but the focusLost of the listener is not called when a cell inside the table is getting edited (it works fine otherwise). I am aware of the client property terminateEditOnFocusLost to solve this problem in 1.4 but I can't use it since I am still on 1.3.1_04.
    Suggestions welcome.

    http://forum.java.sun.com/thread.jsp?forum=57&thread=431440

Maybe you are looking for