Focus Lost when Dragging JInternalFrame?

Hopefully this should be a simple question:
I have a JInternalFrame with numerous simple components like JTextFields.
When I click the title bar, or click and drag the Frame, the JTextField that had focus prior to that clicking loses focus. Focus goes to the Main Frame window, and if I use setFocusable(false) on the main frame, focus goes nowhere (getFocusOwner() == null).
I want focus to remain in the same component (the JTextField) when clicking on the title bar and when dragging. How do I do this?
I'm using jdk1.4.1_01. Thanks for the help!
Joel

I HAVE AN ANSWER!!!
First of all, when you click on the JInternalFrame's title bar, I was losing focus. To fix this, I added a mouse listener to the title bar. I then reset my focus on a mouse clicked event. To find the title bar, I did the following:
private BasicInternalFrameTitlePane findTitleBar()
    Component[] comps = this.getComponents();
    for (int i = 0; i < comps.length; i++)
         if (comps[i] instanceof BasicInternalFrameTitlePane)
              return (BasicInternalFrameTitlePane)comps;
return null;
If the findTitleBar method doesn't return a null, add a mouse listener to it. In the mouseClicked method, reset your focus. I found by using the SwingUtilities.invokeLater, it worked better. So my mouseClicked method looked like:
public void mouseClicked(MouseEvent  e)
   initFocusFor(getFocusComponent());
public void initFocusFor(final JComponent comp )
   if (comp == null)
      return;
   SwingUtilities.invokeLater(new Runnable()
     public void run()
        comp.setRequestFocusEnabled( true );
        comp.requestFocusInWindow();
}Now, for the resizing and dragging.... I was losing my focus on that as well. I believe my desktop manager was getting the focus on resizing and dragging. So, on my subclassed desktop manager, I just added logic to reset my focus on the JInternalFrame on the following methods: endDraggingFrame and endResizingFrame.
Hope this helps someone else.     

Similar Messages

  • Focus lost when pressing ALT key

    Hi,
    is there any way to prevent the focus to be lost when pressing ALT key in an AIR app??
    I tried event.preventDefault() in KEY_UP and KEY_DOWN events but it doesn't work
    when the user press the ALT key, the stage loses the focus
    thanks

    I am now having trouble with the same issue. I have tried removing the ALT key from the Input Map from my frame and the component I'm having trouble with. I have also tried setting my own action in the action map for this. We also tried listening for the key pressed event and putting focus back to the combobox where I want focus to remain. I am now working on trying to use the processKeyEvent method to handle this, but have not had any luck as of yet with that. If anyone has some help on this, I'd greatly appreciate it!

  • 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

  • [1.1.0.22.71 - Linux] Focus lost when prompting for password

    Hi,
    I used to have the same problem on 1.0 from time to time, but with 1.1 it happens every time.
    The problem: When I try to open a connection whose password has NOT been saved, I get two windows: one "progress bar" titled "Connecting to ...", and another dialog titled "Connection Information" prompting me to enter the password. However, the cursor is nowhere to be seen; the keyboard doesn't work at all (neither Enter nor ESC close the dialog); clicking on the edit boxes or blind typing has no effect. Clicking OK then inevitably results in a message saying "A password is required" so the only way out is by clicking "Cancel".
    The only workaround I've found so far was pasting the password using the mouse (middle button).
    There are no exceptions on the console.
    SQL Developer is running on RH Linux:
    os.version     2.4.21-9.ELsmp
    I'm working on an HP/UX workstation and using an X session to the Linux server.
    I've never experienced this problem on the WindowsXP laptop.
    Looking forward to your help,
    Flado

    Marcus,
    is this a standard numeric data, or is this 5502.73 in local form with the"," instead of the "."
    B
    I want to try and get this today as there was another post on exporting in territories other than AMERICA

  • 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

  • Default button is lost when JInternalFrame is iconified

    Hello, everybody!
    Have you already noticed that the default button is lost (loses its characteristics) when the JInternalFrame is iconified? Is there any workaround for this?
    Thank you.
    Marcos

    camickr wrote:
    So you already have a solution from the bug posting.No, because in my case the default button can change over time in the JInternalFrame. If it was fixed I could use the solution in the bug posting. Anyway I found a workaround in my case. I'm using an hierarchy listener to restore the default button. The code in the hierarchyChanged method below is called when the JInternalFrame is deiconified:
    @Override
    public void focusGained(FocusEvent e)
        getRootPane().setDefaultButton(_btnPesquisar);
        _focalizado = true;
    @Override
    public void focusLost(FocusEvent e)
        getRootPane().setDefaultButton(null);
        _focalizado = false;
    @Override
    public void hierarchyChanged(HierarchyEvent e)
        if (_focalizado && (e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0 && isDisplayable())
            getRootPane().setDefaultButton(_btnPesquisar);
    }I just would like to know, as this is a long standing bug, if a more elegant solution was found.
    Marcos

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

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • OK, I need to be able to have a linked TOC, and also have destinations created in FM10 that will not be lost when I 1. Save the book as a PDF. then 2.  need the PDF to be as small as possible, but without losing my destinations. Anyone know how to do that

    OK, I need to be able to have a linked TOC, and also have destinations created in FM10 that will not be lost when I 1. Save the book as a PDF; then 2. I need the PDF to be as small as possible, but without losing my destinations. Anyone know how to do that??
    I had been saving as a PDF and then reducing the size of the PDF by printing it as a PDF with a degree of image compression. I write manuals with a LOT of screen captures and line art that needs to be clear. So it is a balancing act between image clarity and PDF size. The PDFs on the web need to be smaller - sure you can undertsand.
    Anyway, when I print the PDF again, I lose both my destinations and bookmarks.
    Anyone know of any way to avoid that?

    Control the images by creating a custom PDF Job Options and then selecting it in the PDF Job Options drop-down of the PDF setup dialog box (File > Save as PDF...)
    Create the custom PDF Job Options file with Distiller. If you do not have Distiller, open the Printing Preferences of the Adobe PDF printer. Start with the Smallest File Size Job Options settings and Edit.

  • I have a new hard drive on my imac  I want to sync my ipad(which has the files I lost when my old hard drive died), which holds the files I lost when my old hard drive died.  How can I sync my ipad with my new hard drive?

    My hard drive on my IMac died, so I have a new hard drive.  I want to sync my Ipad(which has the files I lost when my old hard drive died) back with my IMac. How can I sync my Ipad with my new IMac hard drive without erasing my legacy files on the Ipad at the same time?

    Copy everything from your backup copy of your cpomputer to your new hard drive.

  • If my  ipod nano already has music on it but not my account will all my stuff be lost when i sync it to my account

    if my ipod nano already has music on it but not on my new account will all my stuff be lost when i sync it to my new accont and would i still be able to add stuff from the old account to my ipod

    All your iTunes Store purchases are linked to the account.  I do not think you can use two accounts with an iPod*, so you will have to choose one account or the other, and use only the things purchased under that account.
    *I've never actually tried, but that's my understanding.  You'd get a better answer by posting in the correct forum.  Try the iPod forums rather than the Using Apple Support Communities forum.

  • How to retrieve all datas that lost when i update my iphone4 to that 6.10 ios. i tried to look at may i tunes in my computer but it seems that i forgot to perform back ups since i purchased this phone 2yirs ago.. pls send me an advice..thank u.

    how to retrieve all datas that lost when i update my iphone4 to that 6.10 ios. i tried to look at may i tunes in my computer but it seems that i forgot to perform back ups since i purchased this phone 2yirs ago.. pls send me an advice..thank u.

    All of the data should be on your computer, simply sync it back.
    If the update was done via iTunes on the computer, the first step in the process is a backup of the device.

Maybe you are looking for