JTable Focus Lost

Hi All,
I have a JTable with 6 columns and the last column has a button attached called EXPAND.
Also I have another navigation buttons called Next, Back, Save and Refresh.
Whenever I make changes to the cell and then click on the expand button of the 6th column, it saves my changes.
but when i make changes to the cell and then click some where else (other than on the JTable) ...here for example on the Refresh button ...and then click on the expand button on JTable, I could not save my changes ...
i.e. it is not invoking my focusLost ...Is there any work around for this problem ...
I am posting my focus Lost code :
public void focusLost(FocusEvent e) {
if (jTable.getSelectedColumn() >= 0) {
if (jTable.getColumnName(jTable.getSelectedColumn()).equalsIgnoreCase("Expand")) {
saveData();
Many Thanks
Mahesh

try tableChange Listener, something like this
class TableListener
       implements TableModelListener {
      private JTable table;
      public TableListener(JTable table) {
      this.table = table;
      public void tableChanged(TableModelEvent e) {
         int editRow = table.getEditingRow();
         String value = table.getValueAt(editRow, 1).toString();
         if (e.getType() == TableModelEvent.UPDATE) {
            save();
[/code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • JTable discards input when focus lost

    Hi! Im running Java 1.4.2-b28.
    Problem as follows:
    I have a JTable where the user can enter som data.
    I also have a button with the caption "Minimize" that starts processing of the same data.
    If i enter a value into the table (say "foo") and press "Minimize" when the cell is in editing mode, "foo" is NOT SAVED into the JTable's TableModel! getValueAt(int row, int col) returns an old value instead!
    How can i change the focus lost behaviour on the cell? Is this a bug??
    Regards
    /Alex

    Found an answer to this, sorry everyone. Well, here it is:
    http://forums.java.sun.com/thread.jsp?thread=350530&forum=57&message=1453945

  • How to handle cell events like focus lost in  jtable

    Hi,
    I have faced a problem relating jtable.Upon focus lost on particular cell the values in the other cells need to change accordingly.Out of 7 columns, upon entering an integer value in one column accordingly 3 columns need to update the values fetched from database and get disabled.The columns being updated have a combobox in which the value is to be shown.....Please look at it and provide a working solution.
    Looking forward,
    chandra

    Try using a TableModelListener:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566133

  • Feature Request: Microsoft Excel 2013 - Don't hide status bar text on focus lost (AVERAGE, COUNT, SUM)

    Could you please disable hiding of status bar text on focus lost.
    I use this in Excel 2013, where I select a few cells, then move to another Excel to write the sum of those cells as read from the status bar or to check with other values in the second window. This really makes my life easier and I see no reason to hide
    the status bar text when the window looses focus.

    Hi,
    Thanks for your suggestions.
    You can also send your feedback to the Office team by the steps as below:
    1. Inside any new Office application you’ll see a yellow smiley face in the top-right corner. Click on the face and choose either
    Send a Smile to send positive feedback or
    Send a Frown to send negative feedback.
    2. In the window that appears, provide details about your feedback or issue. Also, be sure to provide a link to this thread.
    3. Next, you can choose whether or not to send a screenshot. You can also enter your email address so the Office team can contact you directly if they have any questions.
    Note: Most feedback requests do not result in responses from the Office team.
    4. Click the Send button at the bottom of the form to send your feedback.
    Best Regards,
    Judy

  • Focus lost called multiple time

    Hi
    I have created a simple search panel containing a JFormattedTextField
    and a button next to it .
    Now if focus is in JFormattedTextField and user press TAB , focus lost method is called and i have to validate the values , which is very straight forward .
    This focus lost method is being called only <b>once</b> on fedora linux , but is being called <b>thrice</b> on Windows XP .
    Any lead please ?
    Thanks
    Sunny Jain

    Two suggestions:
    1. Use an InputVerifier instead
    http://java.sun.com/javase/6/docs/api/javax/swing/InputVerifier.html
    2. If you insist on taking the FocusListener route, maybe you can check the isTemporary() flag on the FocusEvent? I'm guessing two of the three focus lost events will have isTemporary() == true (but I could very well be wrong).

  • Focus Lost - Sticky Cursor

    Hi folks,
    When using 10gRel2 we get a lot of 'focus lost' problems. I read all threads here and in metalink; this problem is a very serious one and in some cases hard to reproduce. at least 10 different situation causes different focus lost situations.
    Oracle has concentrated that issue in the base bug 5358366.
    The fix for the focus lost problems will be implemented in JRE 1.5.0_9 which is currently not available at SUN. Nevertheless, has anybody received that internal version for testing? What's your experience?
    Thanks, werner

    Hi kndwds,
    Would be very interested in sharing some information re your Focus Lost question. We have had very similar issues in all versions of Forms (and occassionally have managed to create test cases) resulting in a number of patches. In 10.1.2 and the Sun JVM, the issue is very much worse, but currently we can not reproduce a repeatable test case.
    I have reviewed all the bugs, but this does not provide much meaningful information.
    Can you provide any update on the situation with your TAR, and if at all possible, full details of the test case that you have been able to provide.
    Any help much appreciated.
    Regards
    Marc Ludwig

  • Focus lost first ?

    i have 2 text fields, A and B. when i hit tab, focus travel from A to B, my question is which focus event occur first ? focus lost for A or focus gained for B ?

    i have a more complex problem, why i press the tab, the program won't fire the ket event? when i press enter, it fire the key event ? a sample code is provided and anyone can explain the result ?
    Ai got the focus
    key event fired
    Bi got the focus
    Ai lost the focus
    Ai lost the focus
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class test10 implements FocusListener, ActionListener, KeyListener
      private static JFrame frame;
      private static JPanel pane1;
      private static JTextField tfield1, tfield2;
      private static JTextField current = null;
      public test10()
        frame = new JFrame( "A frame" );
        frame.setSize( 100, 50 );
        pane1 = new JPanel();  
        tfield1 = new JTextField( "A", 5 );
        tfield1.setName( "A" );
        tfield1.addFocusListener( this );
        tfield1.addActionListener( this );
        tfield1.addKeyListener( this );
        tfield2 = new JTextField( "B", 5 );
        tfield2.setName( "B" );
        tfield2.setEnabled( false );
        tfield2.addFocusListener( this );
        tfield2.addActionListener( this );
        tfield2.addKeyListener( this );
        pane1.add( tfield1 );
        pane1.add( tfield2 );    
        frame.getContentPane().add( pane1 );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.pack();
        frame.setVisible( true );
      public void keyPressed(KeyEvent e)
    System.out.println( "key event fired" );
        if(e.getKeyCode() == e.VK_TAB)
          if( current == tfield1 )
            tfield1.setEnabled( false );
            tfield2.setEnabled( true );
            tfield2.requestFocus();
          if( current == tfield2 )
            tfield2.setEnabled( false );
            tfield1.setEnabled( true );
            tfield1.requestFocus();
      public void keyTyped( KeyEvent e )
      public void keyReleased(KeyEvent e)   
      public void focusGained( FocusEvent fe )
        System.out.println( ((JTextField)fe.getSource()).getName() + "i got the focus" );
        current = (JTextField)fe.getSource(); 
      public void focusLost( FocusEvent fe )
        if( fe.getSource() == tfield1 )
          tfield2.setEnabled( true );
          tfield2.requestFocus();     
          tfield1.setEnabled( false );
          System.out.println( ((JTextField)fe.getSource()).getName() + "i lost the focus" );   
        if( fe.getSource() == tfield2 )
          tfield1.setEnabled( true );
          tfield1.requestFocus();  
          tfield2.setEnabled( false );  
          System.out.println( ((JTextField)fe.getSource()).getName() + "i lost the focus" );   
      public void actionPerformed( ActionEvent ae )
        if( ae.getSource() == tfield1 )
          tfield1.setEnabled( false );
          tfield2.setEnabled( true );
          tfield2.requestFocus();     
          System.out.println( ((JTextField)ae.getSource()).getName() + "i lost the focus" );   
        if( ae.getSource() == tfield2 )
          tfield2.setEnabled( false );          
          tfield1.setEnabled( true );
          tfield1.requestFocus();
          System.out.println( ((JTextField)ae.getSource()).getName() + "i lost the focus" );   
      public static void main( String[] args )
        test10 t = new test10();
    }

  • Preventing Focus Lost

    I am trying to stop a focus lost on a JTextField. I was not able to find anything on this in the Forum or searching.
    Basically, I want to prevent a user from leaving a text field when the data is invalid, so focus lost should only be granted when valid.
    I tried overriding .transferFocus(), but of course you can just click on another component.
    I did find something that works at times, but is very dangerous. I added a focus listener and did something like this:
                public void focusLost(FocusEvent e)
                    try
                    {                    Toolkit.getDefaultToolkit().getSystemEventQueue().getNextEvent();
                    catch (InterruptedException ex){}
                    requestFocus();
                }Calling this will remove the focus gained event after the focus lost and .requestFocus() can be called to regain focus.
    Anyone have any ideas?

    Check out the InputVerifier class.
    Or, you can also use a [url http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#filter]Document Filter to prevent invalid character from being entered the the text field.
    Or, you can use a JFormattedTextField.

  • Focus lost when a popup menu is activated...

    It seems that when a popup menu is activated the component invoker lost focus. this is ugly because a focus lost can trigger unexpected events (formatting, validating, etc). how can I avoid this?
    thanx

    I must seem a bit weird being the only one to reply to my posts, but I found what is occuring, is that when I do the mouse click the InputVerifier for that JTextField is firing. This is causing a problem, because this input verifier pops up a dialog saying please enter correct values ... and then highlights the entire text field. Problem is if the input is currently invalid I can't use the mouse.
    Any ideas?
    Tom

  • JTable, cells lost focus

    How can I get or listen to event when my cell lost focus ??

    The correct answer is to... well, that should be saved for the Swing forum. or alternatively, its in the text for THE FIRST google result for "jtable cell listener".

  • JTable focus w/ editable headers

    I have three JTables which act as a core, a row header, and a column header, like a spreadsheet. All tables have mutiple columns/row, and all of the cells are editable. I want one cell among all three tables to be selected/editable at one time. I have tried two separate approches.
    1. on focusLost, clear the selection and stopCellEditing.
    2. on focusGained, clear the selections and stopCellEditing in all the other tables.
    The focusLost solution fails because when you are editing a cell and click outside of the table, the focus doesn't get lost.
    The focusGained solution fails because when stopCellEditing is called, that cell regains focus. Now the very cell which I didn't want to have focus has it again.
    I've been working on this for much too long (was up 'til 5am) and am completely stalled. Any ideas?

    Well I've tried something similar to that, but the "cleanup" is where things really mess up. Say every time I get a focusGain event, I store the table it happened in. The next I get one, just check to see if they're the same value and if not unset the others right? Well unfortunately it doesn't work.
    Say I'm editing (with cursor, ie the value hasn't been saved) in table 2. Now I click on table 1. Table 1 tells the other tables to clearSelection() and stopCellEditing() (to save the value which hadn't been). However, as soon as table 2 gets the call to stopCellEditing, it takes back the focus. Like this
    1. Double click table 2; editing
    2. Single click table 1
    3. Table 1 gets focusGained, tells other tables to clear
    4. Table 2 calls stopCellEditing on itself
    Then, because of the stopCellEditing,
    5. Table 1 gets focusLost
    6. Table 2 gets focusGained
    ... but we should be in table 1!!
    If JTable didn't have a bug, then after step 2 table 2 should get a focusLost event, but it doesn't. The more I think about this problem the more I get stuck. Any brainstorming is appreciated!

  • Focus lost in Date Field when the property autosubmit="true" is added

    Hi,
    I am using jdeveloper version 11.1.2.0.0.
    The issue I am facing is when I add the property autosubmit="true" for a date field and if I am selecting a date value using date picker, the focus is lost for the date field. But when I remove the property autosubmit="true" for the date field and if I am selecting a date value using date picker, the focus stays in the date field. This I tried in sample application with the default converter and validator. Anybody can help me with this issue?

    Hi,
    there is a preSubmit event for form objects you can use.
    Select your date field, open the script editor and add this script (language is FormCalc) into the preSubmit event.
    $ = num2date(date(), "MM/DD/YYYY")

  • Focus Lost on Tree Cell Edit

    I am trying to force changes made in a tree cell edit when focus to that tree node has been lost(like on an enter button press) but it always reverts to the old value. i have tried adding a CellEditorListener to force an enter key press on the editingCanceled action but this still reverts the value.
    Anyone have any ideas on how to fix this?
    Thanks.

    Hi,
    Try to use
        call method cl_gui_control=>set_focus exporting control = grid1.

  • Focus lost moving from one form to another in web deployed forms6i

    I have developed an application using forms6i rel 2
    The forms server is installed on windows 2000 and all necessary set up is done on the forms server. Patch 18 is also applied.
    On the client side I am using IE 6 and JRE Java 2 Ver 1.5.0_9-b03
    Everything works fine. But when I navigate from one form to another, the cursor focus is lost. This also happens when I navigate from one block to another block within the same form.
    In such situation when I press Windows button on the key board twice, the cursor reappears. It seems the problem is because the applet window where the forms is running is not refreshed while navigating to different forms.
    Can anybody guide me to solve this problem.
    Thanks
    Kamlesh

    Hi,
    I also have same problem ´but with forms 10g.
    If i set SeprateFrame=True then it works fine. but if applet is inside ie window and i move from this IE window to any other window and come back then focus is set to first menu item.
    whenever user comes back to forms apps, has to click somewhere in applet to activate it, this is so irritating.
    Seems that even oracle does not have any workaround for this, same thing happens on forms demo which is provided by oracle.
    Mehul

  • JTable focused cell

    I have looked all over the javadoc and done some experimentation but cannot figure out how to get the row & col of the "focused cell", the outlined cell that traverses when the tab key is pressed. The AccessibleTable class getSelectedAccessibleRows() and cols methods returns the cell when only 1 row is selected but it returns the row and col ranges when multiple row/cols are selected, not just the cell with the outline.

    Looking over the source for JTable's prepareRenderer method to see how it determines what has focus yielded this possible solution:
    int focusRow = myTable.getSelectionModel().getAnchorSelectionIndex();
    int focusCol = myTable.getColumnModel().getSelectionModel().getAnchorSelectionIndex();Perhaps that will do what you want.

Maybe you are looking for

  • How do I remove my credit card info off my iphone

    I have an iphone 4 and it was working fine until the day I decided to use my MasterCard to download a song. Now I have $30.00 on my itunes card in my phone and it keeps going back to my MasterCard which has no money on it. Has anyone had this same pr

  • Reader not opening links in my PDF doc

    I have an intranet site for our department and I want to link to our Policy & Procedures. The documents are broken down by chapters. So there's a Table of Contents PDF with links to each section (which are also in PDF form) and each section has a lin

  • E bay app

    Hi i have downloaded the update 2.0 software and managed to get a few free apps where is the ebay app that i thought i was getting i have downloaded the remote app and works very well

  • Cropping images, then moving to the next image causes Aperture to freeze

    Title says it all. Every time. Getting really tired of this.

  • IPhone Message Bug

    Hi there; 2 days ago my friend send me a message like below. I think it's a ussd message. I asked him how can you do. But he didnt say me. I investigate internet but i couldnt find anything. if that's bug i think apple have to fix it.. This is the pi