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

Similar Messages

  • 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

  • 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

  • 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

  • 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

  • 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 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Lost first install disc of retail Tiger box set....

    I have lost my first installation disc for Tiger. Still have other two, but lost first one. Any recourse through support to rectify my blunder short of repurchase? Need to do reinstall.

    Hi llewdis, Welcome to Apple's Users Help Users Forums.
    I would call Apple. It will help if you can find your registration number or are registered as owner w Apple. There is probably a fee but much less than a new purchase. As I recall, they are fairly nice about that particularly since you only want one.

  • 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

  • JFileChooser - Selection Highlight lost on Focus Lost

    I have a form with a JFileChooser, a JButton and a JTree. When I select files and that I select another object, the JFileChooser remove the highlight of my selected files (the object still have the list of selected files). So when I reselect the JFileChooser, its look like nothing was selected.
    Is there a setting to keep highlight when the focus is lost?
    Thanks

    U mean these:
    import java.applet.*;
    import java.awt.*;
    public class Cyclus extends Applet {
    public void init() {
    System.out.println("init");
    public void start() {
    System.out.println("start");
    public void update(Graphics g) {
    System.out.println("update");
    public void paint(Graphics g) {
    System.out.println("paint");
    public void stop() {
    System.out.println("stop");
    public void destroy() {
    System.out.println("destroy");
    the problem is that these methods are first called when the event has happent. I need it WHEN it happens....

  • Window Focus Lost After Saving Page - Any Way To Get It Back With Keyboard?

    I've recently begun using Safari for Windows after having used Opera for years, and have run into a problem with window focus that I didn't have with Opera. Specifically, if you save a web page in Safari, you then find that the following functions are no longer available from the keyboard:
    1. Going back to a web page previous to the one that you just saved. Ctrl+[ does not function.
    2. Performing a search. Ctrl+F does not function.
    3. Scrolling to the bottom or top of the page. Ctrl+End and Ctrl+Home do not function. (For some reason, however, the PageUp and PageDown keys do still work in this situation.)
    Why is this, and more importantly, is there a quick and easy way that you can, using only the keyboard, regain the window focus so that these functions will work again? I'm currently having to click somewhere on the page I've just saved in order to regain the focus. This is a nuisance.
    Thanks for any advice.
    George
    Message was edited by: safwin

    Thanks very much. Hitting 'Alt' button after saving the page does resolve the first (and most important) two of the three issues I listed above. FWIW, the Ctrl+End and Ctrl+Home functions only work in this post-save scenario (as I discovered by experimenting a few minutes ago) if you hit the 'Alt' button twice (or if you do something else, like perform a search and then use Ctrl+End/Home).
    By the way, before posting a few days ago, I had tried using the Alt+Tab method when I had two or more applications' windows open, and it didn't help. But, after reading your last post, I've found that if you use Alt+Tab when Safari is the only window open, then it does resolve the issue, although of course, as you've indicated, it's not actually necessary to hit the 'Tab' key.
    Thanks again!
    George
    Message was edited by: safwin

  • Focus on first item on the page

    Allthough I have this setting activated for my login page and my first item is user name, the focus is set to password. Is there anything I forgot? Funny enough, on one of my other applications works right.
    Denes Kubicek

         What is the difference between these ways:
    onLoad="html_GetElement('P101_USERNAME').focus();"
    And
    <script type="text/javascript">
    first_field('P101_USERNAME');
    </script>
         For some reason, I was able to set the focus by using the second method, but never success on first. Could you or someone to help me undsertand what the
    possible reason is. What I did is : set Cursor focus to <b>do not focus cursor</b> and put onLoad="html_GetElement('P101_USERNAME').focus();" into Page HTML Body Attribute.
    I am also check the #ONLOAD# on my page template .
        Another question is: I have an item on a page which is a text field. It's focused every time page is loaded. but I put a "onChange" event on this item which calls a
    confirm message box. If "Yes", then submit the page, If "No", clear the item and set the focus on the item again. I am having trouble to have the cusor re-focus on
    the item again. Anyone could help. Thanks in advance for the help. Here is the code I put at page attribute;
    <script language="JavaScript1.1" type="text/javascript">
    function test(form){
       var conmod = confirm("Are you sure you want to submit");
       if (conmod == true)
          doSubmit();
       else
       form.P2_BE.focus() ;
       form.P2_BE.value='';
    </script>
    I am using version 1.6
    Regards,
    Ran

  • 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")

Maybe you are looking for

  • How can I download a file over the internet from a WebDAV server?

    I am trying to download a file over the internet from a WebDAV server. I've tried doing it with Datasocket as suggested in these articles, <a href="http://digital.ni.com/public.nsf/websearch/f3cc5f7e60a75cb2862567e700696abf?opendocument">Retrieving a

  • Field to make uneditable only for the current/selected row

    I have a web dynpro application and I  wanted to make some fields uneditable and for this I have done the following: I bound a context attribute to the readOnly property of all the fields you want to control. Then in the onEnter event of the main fie

  • How to go for deployment

    i have joined as a software trainee in a company,,we are all together 4 people to work for the company's internal project.Company wants to automise its hardware division ,,that means that its clients can buy components from his company over the web,

  • Using Substitution Variable in Web forms

    Hi, I'm trying to use substitution variable in a planning web form &CurYr in the Column, after creating the form when I save it and try to open the form it says the substitution variable required for this calculation is undefined .Variable : &CurYr.I

  • Draw AP Div location problem

    I am pretty new to web design, and I am creating a site use the 'Design' window.  I have everything else working properly on my site, but when I draw an AP Div to place a rollover link, it does not remain in its correct location in relation to the re