Losing keyboard focus  when resetting

I have Player object which is focusable and works fine. However when I try to reset the object with following code:
     public void reset(){
          t.stop();
          remove(player);
          player = new Player(50,60);
          add(player);
          x=50;y=60;
          t.start();
          System.out.println("reset");
     }I lose the focus on player. Everything else works fine but player isn't getting any keyevents after the reset.

Ok here's sscce
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class resetTest extends JPanel{
Player player = new Player();
     public static void main(String[] args){
          JFrame f = new JFrame("resetTest");
          f.add(new resetTest());
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.pack();
          f.setVisible(true);
     public resetTest(){
          add(player);
     public Dimension getPreferredSize(){
          return new Dimension(200,200);
     public void reset(){
          remove(player);
          player = new Player();
          add(player);
          System.out.println("reset");
     class Player extends JPanel implements KeyListener{
          public Player(){
               this.setBorder(BorderFactory.createLineBorder(Color.black));
               this.setFocusable(true);
               this.addKeyListener(this);
          public void keyPressed(KeyEvent e){
               System.out.println(e.getKeyCode());
               if(e.getKeyCode() == 10){ ((resetTest)getParent()).reset();}
          public void keyReleased(KeyEvent e){}
          public void keyTyped(KeyEvent e){}
}If you run this you'll notice that it notices key presses fine, but when you reset it with enter key it stops working.

Similar Messages

  • JComboBox popup list remains open after losing keyboard focus

    Hi,
    I have noticed a strange JComboBox behavior. When you click on the drop down arrow to show the popup list, and then press the Tab key, the keyboard focus moves to the next focusable component, but the popup list remains visible.
    I have included a program that demonstrates the behavior. Run the program, click the drop down arrow, then press the Tab key. The cursor will move into the JTextField but the combo box's popup list is still visible.
    Does anyone know how I can change this???
    Thanks for any help or ideas.
    --Yeath
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    public class Test extends JFrame
       public Test()
          super( "Test Application" );
          this.getContentPane().setLayout( new BorderLayout() );
          Box box = Box.createHorizontalBox();
          this.getContentPane().add( box, BorderLayout.CENTER );
          Vector<String> vector = new Vector<String>();
          vector.add( "Item" );
          vector.add( "Another Item" );
          vector.add( "Yet Another Item" );
          JComboBox jcb = new JComboBox( vector );
          jcb.setEditable( true );
          JTextField jtf = new JTextField( 10 );
          box.add( jcb );
          box.add( jtf );
       public static void main( String[] args )
          Test test = new Test();
          test.pack();
          test.setVisible( true );
          test.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }

    ran your code on 1.5.0_3, observed problem as stated.
    even though the cursor is merrily blinking in the textfield, you have to click into
    the textfield to dispose the dropdown
    ran your code on 1.4.2_08, no problems at all - tabbing into textfield immediately
    disposed the dropdown
    another example of 'usual' behaviour (involving focus) breaking between 1.4 and 1.5
    the problem is that any workaround now, may itself be broken in future versions

  • Illustrator CS6 loses keyboard focus when using an extension panel

    OS10.8.2 CS6. When clicking a button on any extension panel (even supplied Kuler), it seems that Illustrator can't get keyboard focus until something else on the screen is clicked. Anyone know a way to fix this? I need to be able to use the keyboard to copy or delete a selected object right after running script....
    Tried running a javascript inline with app.activate() command. Didn't work. Help!!!!

    I noticed the problem too. Is there any fix or workaround? Friends using Windows say that all is ok.
    Linux x86_64 (Gentoo), Firefox 3.5.1, jre 1.6.0.15.

  • Cannot set focus when reset data using datasets

    Hi All,
    When I click reset form button. I would like to reset data then focus to the first field. I can clear information I provided but setFocus to the first name field is not working. Please help.
    I use datasets to reset data. 
    Here is my coding:
    event: click
    xfa.datasets.data.loadXML("<form1/>", true, true);
      xfa.host.setFocus("xfa.form1.contactInformation.firstname")
    Thanks,
    Cindy

    I tested the clear button. But it is not set Focus to the first field. It is not successful.

  • Regaining keyboard focus

    Hello
    I am having a problem with my application. When it is first started it asks for a key press. Or instead you can select something from a JComboBox. If you press a key, it works fine and everything happens as it's supposed to happen. If however, you select something from the JComboBox, something strange occurs and you can no longer press keys as you could just a minute ago. I believe this is because the JComboBox gets the keyboard focus when you use it. This causes the JFrame to lose it's key listening capabilities. How can I solve this problem?
    2 Duke Dollars available.
    Regards
    Jiby

    cud u pls post ur code here

  • TextBox losing its text when focus changed?

    Hi all,
    Im developing a plugin in Illustrator CS3 using VisualStudio 2005.
    I design my dialog using ADM in VS.
    The textbox losing its text when focus is changed.
    In my dialog i have a textbox,checkbox and a ok and cancel button.
    In case, if i enter the text and press tab or the checkbox (before moving the focus to ok or cancel button) the text remains uncleared.
    But if i enter the text and move the mouse to ok or cancel button the text box value gets cleared.
    Please someone guide me to solve this problem.
    Thanks in advance,
    Poovili

    Yeah its working when removing the setdrawproc..
    But we need this setdrawproc..Because we save the project settings and next time we load the project the values'll automatically come up using this dialogdrawproc in setdrawproc..the following is our dialogdrawproc code
    static void ASAPI DialogDrawProc( ADMDialogRef dialog,ADMDrawerRef drawer)
        ADMItemRef ItemRef;
        if(dialog==g->qcCheckDialog )
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtOverprint);
            sADMItem->SetText(ItemRef,g->BlackValues);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtTintValues);
            sADMItem->SetText(ItemRef,g->TintValues  );
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtRuleThickness);
            sADMItem->SetText(ItemRef,g->RuleThickNess  );
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtDashGap1);
            sADMItem->SetText(ItemRef,g->DashGapValues  );
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtPatterns);
            sADMItem->SetText(ItemRef,g->PatternValues  );
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtLeadTextSize);
            sADMItem->SetText(ItemRef,g->LeadTextSize  );
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtSuperscript);
            sADMItem->SetText(ItemRef,g->SupValue );   
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtSubscript);
            sADMItem->SetText(ItemRef,g->SubValue );
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtBitmapResFrom);
            sADMItem->SetText(ItemRef,g->BitmapResFrom);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtGrayScaleResFrom);
            sADMItem->SetText(ItemRef,g->GrayscaleResFrom);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtCMYKResFrom);
            sADMItem->SetText(ItemRef,g->CMYKResFrom);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtBitmapResTo);
            sADMItem->SetText(ItemRef,g->BitmapResTo);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtGrayScaleResTo);
            sADMItem->SetText(ItemRef,g->GrayscaleResTo);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtCMYKResTo);
            sADMItem->SetText(ItemRef,g->CMYKResTo);
            //-------------TYPE AREA---------------------------------
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtAreaWD);
            sADMItem->SetText(ItemRef,g->TAreaWD);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtTAHeight2);
            sADMItem->SetText(ItemRef,g->TAAreaHt);
                            //column size
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtColumn1Height);
            sADMItem->SetText(ItemRef,g->Column1Height);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtColumn1Width);
            sADMItem->SetText(ItemRef,g->Column1Width);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtColumn2Height);
            sADMItem->SetText(ItemRef,g->Column2Height);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtColumn2Width);
            sADMItem->SetText(ItemRef,g->Column2Width);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtColumn3Height);
            sADMItem->SetText(ItemRef,g->Column3Height);
            ItemRef=sADMDialog->GetItem(g->qcCheckDialog ,txtColumn3Width);
            sADMItem->SetText(ItemRef,g->Column3Width);
            //sADMDialog->Draw(drawer);
            //admDialog->Draw(drawer);
            //-------------SAVE SETTINGS--------------------------------
        if(dialog==g->LoginSaveSettingsDialog)
            ItemRef=sADMDialog->GetItem(g->LoginSaveSettingsDialog ,txtLSSUser1);
            sADMItem->SetText(ItemRef,g->TxtLSSUser1);
            ItemRef=sADMDialog->GetItem(g->LoginSaveSettingsDialog ,txtLSSPassword);
            sADMItem->SetText(ItemRef,g->TxtLSSPassword);
        //-----------------ADD NEW USER-----------------------------------
        if(dialog==g->AddNewUserDialog)
            ItemRef=sADMDialog->GetItem(g->AddNewUserDialog ,txtLogin1);
            sADMItem->SetText(ItemRef,g->TxtLogin1);
            ItemRef=sADMDialog->GetItem(g->AddNewUserDialog ,txtPassword);
            sADMItem->SetText(ItemRef,g->TxtPassword);
        if(dialog==g->AddingUsertoDBDialog)
            ItemRef=sADMDialog->GetItem(g->AddingUsertoDBDialog ,txtNeuUser);
            sADMItem->SetText(ItemRef,g->TxtNeuUser);
            ItemRef=sADMDialog->GetItem(g->AddingUsertoDBDialog ,txtCreateNewPassword);
            sADMItem->SetText(ItemRef,g->TxtCreatePassword);
        //-------------------------Change Password-----------------------
        if(dialog==g->ChangePasswordDialog)
            ItemRef=sADMDialog->GetItem(g->ChangePasswordDialog ,txtCPLogin);
            sADMItem->SetText(ItemRef,g->TxtCPLogin1);
            ItemRef=sADMDialog->GetItem(g->ChangePasswordDialog ,txtCPOldPass);
            sADMItem->SetText(ItemRef,g->TxtCPOldPass);
            ItemRef=sADMDialog->GetItem(g->ChangePasswordDialog ,txtCPNewPass);
            sADMItem->SetText(ItemRef,g->TxtCPNewPass);
            ItemRef=sADMDialog->GetItem(g->ChangePasswordDialog ,txtCPConfirmPass);
            sADMItem->SetText(ItemRef,g->TxtCPConfirmPass);
        if(dialog==g->SelectProjDialog)
             if (CyanToMagBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            /*else if(RasterColorsBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if(RasterColorsBool==true)
                dialog = sADMItem->GetDialog(ItemRef);
                if (ItemRef==sADMDialog->GetItem(dialog, txtAssessmentPath1))
                    sADMItem->GetText(ItemRef,g->ConversionFolderPath ,1024);
                    sADMItem->SetText(ItemRef,g->ConversionFolderPath );
                    //MessageBox(NULL,g->BlackValues,"Txt",0);
           else if(SaveAdvancedAssessBool == true)
               ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->AssessmentFolderPath);
            else if(ConvertSwatchBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath);   
            else if(DrawBBBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtBBSpacing);
                sADMItem->SetText(ItemRef,g->BBSpacing );
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtBBStrokeWidth);
                sADMItem->SetText(ItemRef,g->BBStrokeWidth );   
            else if(ConvertGradientBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if (PantoneToCyanBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if (QceraBatchConversionBool1==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if (PantoneToMagentaBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if(SaturationBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if(ColorOverprintBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            //else if(ColorsBatchBool==true)
            if(sADMItem->GetBooleanValue( sADMDialog->GetItem( g->SelectProjDialog, CHK_CheckColors1 ))==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if (ConvertFontsBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
                else if(FontCorrectionBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if(ScalingBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->ConversionFolderPath );
            else if(SaveAssessBool==true)
                ItemRef=sADMDialog->GetItem(g->SelectProjDialog ,txtAssessmentPath1);
                sADMItem->SetText(ItemRef,g->AssessmentFolderPath);
                //MessageBox(NULL,g->AssessmentFolderPath,"Assess",0);
    //MessageBox(NULL,g->ConversionFolderPath,"Assess",0);
        if(dialog==g->CleanDialog)
            if(CleanArtBatchConversionBool==true)
            ItemRef=sADMDialog->GetItem(g->CleanDialog ,txtLeadingValue);
            sADMItem->SetText(ItemRef,g->leadingValue  );
            ItemRef=sADMDialog->GetItem(g->CleanDialog ,txtBlackValues);
            sADMItem->SetText(ItemRef,g->ApplyBlackValues  );
            ItemRef=sADMDialog->GetItem(g->CleanDialog ,txtCleanArt_SpecifyFolder1);
            sADMItem->SetText(ItemRef,g->CleanArtFolderPath );
    Let me know if i'm not clear. Thanks in advance..

  • Tab to move keyboard focus

    Okay, I've been looking around for quite some time and cannot find a solution for my annoying problem: I cannot keep the 'Tab to move keyboard focus between: All controls' to stick. I am able to change the keyboard setting so that the Tab key changes keyboard focus through settings -> keyboard -> keyboard shortcuts -> full keyboard access and the simple control+F7 until I log out, reboot or power cycle.
    I have reset all of my keyboard settings to default and I have gone so far as to create a new user with admin priviledges but the problem persists. Any ideas?
    I appreciate any input you may have!

    More info in case anyone is reading (I feel as though this is a one person conversation).
    I backed my MBP up and reinstalled Lion and still have the problem after a restore. I did the reboot -> command-R trick and reset priviledges but to no avail and I am beginning to think this is a bug.
    The last thing I will add is under Keyboard -> Keyboard Shortcuts, Full Keyboard Access is granted to All controls and does not reset when I reboot and am unable to change keyboard focus with tab.

  • Bug Report: The keyboard focus doesn't automatical...

    Bug Report: When a conversation window opens, the focus doesn't automatically land in the chat entry text field.
    Since the new interface for Skype was introduced officially in Skype 7.0, there is a bug with the system/keyboard focus for a new conversation window. When Skype is in "Split Window View" and each new conversation automatically pops up in a separate window, the system/keyboard focus doesn't land in the chat entry edit field. Instead, the user has to press Shift+TAB a couple of times, to move it there and reply to the chat message received. This especially problematic for screen reader users, who rely on keyboard navigation. This mainly occurs when a new conversation is started with an incoming message, but it sometimes occurs when moving the focus out of that conversation window and later back in it again (while it is still opened).
    Steps to reproduce it:
    1. From "View" menu, activate the "Split Window View", if it is not already enabled.
    2. From Tools -> Options -> IM & SMS -> IM settings, enable "Open a new window when I receive a new message in Split Window View", if it is not already enabled.
    3. From Tools -> Options -> Advanced, activate "Enable accessible mode", if it is not already enabled.
    4. Activate the "Save" button, to save the changes.
    5. Close all windows, related to Skype. You may keep only the main window opened.
    6. Tell someone to send you a chat message. When the message arrives, Move the system focus to the conversation window in question, preferably with Alt+TAB. The system/keyboard will not land in the chat entry edit field as it did in Skype 6.21 and earlier and as it should by default, but in some unknown place in the window.
    7. Move the system/keyboard focus in the chat entry edit field and keep it there.
    8. Switch to another window, preferably from another application.
    9. With Alt+TAB, switch back to the window of the opened Skype conversation. There is a chance that the system/keyboard focus will not land in the chat entry edit field as it did in Skype 6.21 and earlier and as it should do by default, but again in some unknown place in the conversation window. But that is harder to reproduce.
    Test environment:
    - Operating system: Windows 8.1 Pro N, 64-bit, in Bulgarian with all locale settings set to "Bulgarian".
    - Skype version: 7.0.0.102 for Desktop.

    This is a known problem, but Skype have not given us an estimated time for a fix.
    Traditionally, Skype updates have been roughly monthly, so we are due a new version sometime soon. Many of us here are hoping that is has a bunch of fixes for the UI, the focus problem being one of them.
    Sean Ellis - uses Skype chat for serious work
    Click here to read my blog post on Skype 7 and basic principles of GUI design

  • Loss of keyboard focus in Java appl running under linux

    I have a small sample program that replicates my problem. When this program is run a window is created. If you select File->New another instance of the program window is created. Now if you try to go back and bring to front the first window, keyboard focus is not
    transferred when run under linux. You can only type in the second window. The expected behavior does happen in Windows.
    > uname -a
    Linux watson 2.6.20-1.2933.fc6 #1 SMP Mon Mar 19 11:38:26 EDT 2007 i686 i686 i386 GNU/Linux
    java -versionjava version "1.5.0_11"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
    javac -versionjavac 1.5.0_11
    import java.awt.event.*;
    import javax.swing.*;
    class SwingWindow extends JFrame {
        SwingWindow() {
         super("SwingWindow");
         JMenuBar menuBar = new JMenuBar();     
            JMenu fileMenu = new JMenu("File");
            JMenuItem newItem = new JMenuItem("New");
            newItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
              SwingWindow.createAndShowGUI();
         fileMenu.add(newItem);
            menuBar.add(fileMenu);
            setJMenuBar(menuBar);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);       
         JTextField text = new JTextField(200);
         getContentPane().add(text);
         pack();
         setSize(700, 275);
        public static void createAndShowGUI() {
            JFrame frame = new SwingWindow();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    You can implement the FocusListener interface. When
    the first JFrame gains focus, call
    text.requestFocusInWindow(). I hope this helps.The call requestFocusInWindow is not helping, perhaps even making it worse.
    The problem seems to be that I am in the situation where the call
    KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()
    is returning the expected Component. The problem is that the KeyListener class that is registered with the Component is not being called when a key is being pressed.
    The issue is that I have a component that has the keyboard focus, but the KeyListener class
    is not responding.
    This seems to be a linux only problem which makes it only mysterious.

  • JPanel loses keyboard focus

    Ok, i have a JTextField which is initially disabled. A JPanel draws some stuff and receives keyboard input. When i enable the textfield, type some stuff, then press Esc (which disables it), i cant get the keyboard focus back on the JPanel. Here is an example:
    (you can move the red circle before you enable the textfield, after you disable it, you cant move it anymore).
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.util.Vector;
    public class example extends JPanel implements ActionListener,Runnable {
        JFrame frame;
        JMenuBar menubar;
        JMenu m_file;
        JMenuItem mi_open,mi_close;
        JPanel canvas,northpanel;
        JTextField textfield;
        Image canvasimg;
        Thread thread=new Thread(this);
        private Image dbImage;     // for flickering
         private Graphics dbg;     // for flickering
         int x1=400,y1=200;
        public example() {
            frame = new JFrame("Example");                         // window
            frame.setLayout(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setPreferredSize(new Dimension(1000,700));
            frame.setLayout(new BorderLayout());
            northpanel=new JPanel();
            northpanel.setLayout(null);
            northpanel.setPreferredSize(new Dimension(1000,20));     northpanel.setLocation(0,0);
            menubar=new JMenuBar();
            m_file=new JMenu("File");   
            mi_open=new JMenuItem("Open");
            mi_close=new JMenuItem("Close");
            m_file.add(mi_open);
            m_file.add(mi_close);   
            m_file.getPopupMenu().setLightWeightPopupEnabled(false);   
            menubar.add(m_file);
            northpanel.add(menubar);
            menubar.setLocation(0,0);     menubar.setSize(80,20);
            textfield=new JTextField();
            northpanel.add(textfield);
            textfield.setSize(200,20);     textfield.setLocation(500,0);   
            textfield.setEnabled(false);
            frame.add(northpanel,BorderLayout.NORTH);
            canvas=new JPanel();
            canvas.setLayout(null);
            canvas.setSize(1000,600);
            canvas.setBackground(Color.white);
             frame.add(canvas,BorderLayout.CENTER);      
            frame.pack();
            frame.setVisible(true);       
            thread.start();                                   // start the thread
            textfield.addMouseListener(new MouseAdapter(){
                    public void mousePressed(MouseEvent e){
                         textfield.setEnabled(true);
               textfield.addKeyListener(new KeyAdapter() {
                 public void keyPressed(KeyEvent e){
                      int key=e.getKeyCode();
                      if(key==27){     // esc
                           textfield.setEnabled(false); 
                           canvas.setEnabled(true);                // not working
                           canvas.requestFocus();
                           canvas.requestFocusInWindow();
               frame.addKeyListener(new KeyAdapter() {
                 public void keyPressed(KeyEvent e){                   
                      int key=e.getKeyCode();
                      if(key==37){ //left
                           x1-=5;
                      if(key==38){ //up
                           y1-=5;
                      if(key==39){ //right
                           x1+=5;
                      if(key==40){ //down
                           y1+=5;
        // Create the GUI and show it. 
        private static void createAndShowGUI() {
            JFrame.setDefaultLookAndFeelDecorated(true);
            example ex = new example();
        public void run(){
             while(true){
                  try{
                       if(canvasimg==null)repaint();                   
                       Graphics g=canvas.getGraphics();
                       update(g);
                       thread.sleep(30);                                             // 1 sec
                  }      catch(InterruptedException ex){}
        // ActionPerformed handles button and menu events
        public void actionPerformed(ActionEvent e){              
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        public void update (Graphics g){          // get rid of flicker
              if (dbImage == null){
                   dbImage = canvas.createImage (canvas.getSize().width, canvas.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (canvas.getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (canvas.getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
         public void paint(Graphics g){
              g.drawImage(canvasimg,0,0,this);          
              g.setColor(Color.red);
             g.fillOval(x1,y1,10,10);
        public void repaint(){     
             if(canvas!=null && canvasimg==null)canvasimg=canvas.createImage(1000,670);
             if(canvasimg==null)return;
             Graphics g=canvasimg.getGraphics();
             if(g==null)return;
             g.setColor(Color.white);
             g.fillRect(0,0,1000,600);
    }  

    OK great guru since you're so damn confident that you're doing everything right, find out for yourself why this works and yours doesn't.
    I could list a few dozen things wrong with your code, but I'd be wasting my keystrokes.import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class TextFieldDisableNoProblem extends JPanel {
       JPanel northPanel;
       JMenuBar menubar;
       JMenu m_file;
       JMenuItem mi_open,mi_close;
       JTextField textField;
       int x1 = 400;
       int y1 = 200;
       public TextFieldDisableNoProblem () {
          setBackground (Color.WHITE);
          addKeyListener (new KeyAdapter () {
             public void keyPressed (KeyEvent e){
                int key = e.getKeyCode ();
                switch (key) {
                   case KeyEvent.VK_LEFT:
                         x1 -= 5;
                         break;
                   case KeyEvent.VK_UP:
                         y1 -= 5;
                         break;
                   case KeyEvent.VK_RIGHT:
                         x1 += 5;
                         break;
                   case KeyEvent.VK_DOWN:
                         y1 += 5;
                         break;
                repaint ();
       void makeUI () {
          JFrame frame = new JFrame ("");
          frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          frame.setSize (600, 500);
          frame.setLocationRelativeTo (null);
          menubar=new JMenuBar ();
          m_file=new JMenu ("File");
          mi_open=new JMenuItem ("Open");
          mi_close=new JMenuItem ("Close");
          m_file.add (mi_open);
          m_file.add (mi_close);
          menubar.add (m_file);
          frame.setJMenuBar (menubar);
          textField=new JTextField ();
          textField.setEnabled (false);
          textField.setBounds (200, 0, 200, 20);
          textField.addMouseListener (new MouseAdapter (){
             public void mousePressed (MouseEvent e){
                textField.setEnabled (true);
          textField.addKeyListener (new KeyAdapter () {
             public void keyPressed (KeyEvent e){
                int key = e.getKeyCode ();
                if(key == KeyEvent.VK_ESCAPE){
                   textField.setEnabled (false);
                   requestFocus ();
          northPanel=new JPanel ();
          northPanel.setLayout (null);
          northPanel.setPreferredSize (new Dimension (600,20));
          northPanel.add (textField);
          frame.add (northPanel,BorderLayout.NORTH);
          frame.add (this, BorderLayout.CENTER);
          frame.setVisible (true);
          requestFocus ();
       public void paintComponent (Graphics g) {
          super.paintComponent (g);
          g.setColor (Color.RED);
          g.fillOval (x1, y1, 10, 10);
       public static void main (String[] args) {
          SwingUtilities.invokeLater (new Runnable () {
             public void run () {
                JFrame.setDefaultLookAndFeelDecorated (true);
                new TextFieldDisableNoProblem ().makeUI ();
    }db

  • My MacBook Pro Retina's Bluetooth chipset unknown/odd login message on the login screen states Login Window Authentication Login window Name edit text has keyboard focus. In addition, the login screen is not remembering me

    I have been experiencing several issues with my MacBook Pro Retina mid 2012. My MBPR is scheduled to go into the depot. However, I am wondering if anyone may be able to shed light on a few issues as this is the third "official" time my MBPR is going back for service ("one depot" trip; "one authorized" dealer; several in-store visits).
    My Bluetooth is stating that the Bluetooth Chipset is Unknown (0). I also have had Bluetooth Preferences mysteriously change on me. In addition, while Bluetooth is off there are two serial modems turning on. I have turned them off, but they continue to pop up.
    In addition, when I log in, my MBPR is not remembering me and my login name is not appearing on the slate-gray screen. The name and password are blank and the following message appears in the lower left hand corner. "login window authentication login window Name edit text has keyboard focus."  As a side note, I am the only user. The login issue is a recent occurrence as we just totally wiped it again via a Command + R, and I don't believe I have an accessibility setting set to anything that would cause this, but wanted to check.
    Should I be concerned here? Has anyone else had issues like this? I don't want to worry if I don't have to. I have had so many issues over the course of nine months. 5-6 wipes. Airport card replaced and I am about to pull my hair out if my MBPR doesn't come back worldly like clock work this time. I just can't send my days trying to get a $2300 product to work for me any longer. No idea what is wrong with it, but it is driving me insane. Cross your fingers for me and any guidance you have or thoughts would be welcomed. Thank you. EMM

    A few more issues...
    In Console, the following is greyed out:
    User and Diagnostic reports
    Com.apple.launchd.peruser.0
    Com.apple.launchd.peruser.88
    Com.apple.launchd.peruser.89
    Com.apple.launchd.peruser.92
    Com.apple.launchd.peruser.97
    Com.apple.launchd.peruser.200
    Com.apple.launchd.peruser.201
    Com.apple.launchd.peruser.202
    Com.apple.launchd.peruser.212
    *[user logs are accessible]
    Krb5kdc
    Radius
    My guest files are locked, but again I am the administrator of MBPR.
    I am worried about a keystroke logged or at least, trying to rule it out.
    Also:
    Mdworker32(225) [and other mdworker numbers] are sandboxing; stating deny Mach-lookup
    Com.apple.Powermanagement.control, etc. long attachment with those files with version: ??? (???).
    Postinstall: removing applications/Microsoft Office 2011/Microsoft Outlook.app
    WARNINGS in Console include:
    [NSImage compositeToPoint:fromRect:operation:fraction:] is deprecated in MacOSX 19.8 and later. Please use -[NSImage drawAtPoint:fromRect:operation:fraction] instead.
    There are a ton of other warnings. Before I go through this again, can someone tell me if this is normal (all of it -- above too); or if these are symptoms is a keystroke logger or hardware issues? 
    I ask because originally, when my computer went in for diagnostics (more than once), Apple stated the hardware was fine (other than Airport Card -- finally). However, if I've done 5-6 total wipes; created new users; do not have sharing set-up; have not played around in Terminal; and am up-to-date with versions -- and various issues KEEP COMING BACK -- I am left wondering if a keystroke logger would be possible here?!? I thought maybe a faulty logic board, but why would diagnostics be okay, then? Not trying to be hyperbole, just desperate.
    Please help me rule keystroke logger out or at least, tell me so I know, so I can take appropriate action. If you think it could be the logic board with symptoms above, that would be a great too.
    All I want to do is use the computer as intended, but I can't seem to get a real answer, so after nine months -- I am turning to the communities to see if anyone -- anyone at all -- can help. The last thing I can do is have the MBPR come back from the depot and the same thing occur. Any guidance or advice would be so gratefully appreciated.

  • Calling1.4.1 signed applet from Javascript causes keyboard/focus problems

    Pretty sure there's a JRE bug here, but I'm posting to forums before I open one in case I'm missing something obvious :-)
    This issue may be specific to IE, I haven't tested elsewhere yet. Our web application is centered around a signed applet that is initialized with XML data via Javascript. We first noticed the problem when our users started upgrading from the 1.3.x plug-in to the 1.4.x plug-in. The major symptom was that shortcut keys stopped working. I debugged the problem off and on for about a month before I boiled it down to a very simple program that demonstrates the issue (included below). Basically, the program has a function that adds a JButton to a JPanel and registers a keyboard listener (using the new DefaultKeyboardFocusManager class) that prints a message to the console. This function is called by the applet's init() method, as well as by a public method that can be called from Javascript (called callMeFromJavascript()). I also included a very simple HTML file that provides a button that calls the callMeFromJavascript() method. You can test this out yourself: To recreate, compile the class below, JAR it up, sign the JAR, and put in the same dir with the HTML file. Load the HTML file in IE 5.0 or greater, and bring the console up in a window right next to it. Now click the button that says init--you should see the small box appear inside the button that indicates it has the focus. Now press some keys on your keyboard. You should see "KEY PRESSED!!!" appearing in the console. This is proper behavior. Now click the Init Applet from Javascript button. It has removed the button called init, and added one called "javascript". Press this button. Notice there is no focus occurring. Now press your keyboard. No keyboard events are registered.
    Where is gets interesting is that if you go back and make this an unsigned applet, and try it again, everything works fine. This bug only occurs if the applet is signed.
    Furthermore, if you try it in 1.3, signed or unsigned, it also works. So this is almost certainly a 1.4 bug.
    Anyone disagree? Better yet, anyone have a workaround? I've tried everything I could think of, including launching a thread from the init() method that sets up the components, and then just waits for the data to be set by Javascript. But it seems that ANY communication between the method called by Javascript and the code originating in init() corrupts something and we don't get keyboard events. This bug is killing my users who are very reliant on their shortcut keys for productivity, and we have a somewhat unique user interface that relies on Javascript for initialization. Any help or suggestions are appreciated.
    ================================================================
    Java Applet (Put it in a signed JAR called mainapplet.jar)
    ================================================================
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MainApplet extends JApplet implements KeyEventDispatcher
        JPanel test;
        public void init()
            System.out.println("init called");
            setUp("init");
        public void callMeFromJavascript()
            System.out.println("callMeFromJavascript called");
            setUp("javascript");
        private void setUp(String label)
            getContentPane().removeAll();
            test = new JPanel();
            getContentPane().add( test );
            JButton button = new JButton(label);
            test.add( button );
            test.updateUI();
            DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
        public boolean dispatchKeyEvent(KeyEvent e)
            System.out.println("== KEY PRESSED!!! ==");
            return false;
    }================================================================
    HTML
    ================================================================
    <form>
    <APPLET code="MainApplet" archive="mainapplet.jar" align="baseline" id="blah"
         width="200" height="400">
         No Java 2 SDK, Standard Edition v 1.4.1 support for APPLET!!
    </APPLET>
    <p>
    <input type="button" onClick="document.blah.callMeFromJavascript();" value="Init Applet via Javascript">
    </form>

    I tried adding the requestFocus() line you suggested... Same behavior.
    A good thought, but as I mention in my description, the applet has no trouble gaining the focus initially (when init() is called). From what I have seen, it is only when the call stack has been touched by Javascript that I see problems. This is strange though: Your post gave me the idea of popping the whole panel into a JFrame... I tried it, and the keyboard/focus problem went away! It seems to happen only when the component hierarchy is descended from the JApplet's content pane. So that adds yet another variable: JRE 1.4 + Signed + Javascript + components descended from JApplet content pane.
    And yes, signed or unsigned DOES seem to make a difference. Don't ask me to explain why, but I have run this little applet through quite a few single variable tests (change one variable and see what happens). The same JAR that can't receive keyboard events when signed, works just fine unsigned. Trust me, I'm just as baffled as you are.

  • Switching windows in Linux/Firefox loses keyboard focus. Workarounds?

    Hi,
    I've been stumbling on an issue in which an applet gets into a state where it can receive mouse events but not keyboard events. This state occurs some of the time when switching from a non-modal dialog to the applet.
    I've witnessed this behavior on:
    Linux (fc8), Firefox 3.0.10, Java plug-in 1.6.0_13, Gnome 2.20.3
    Sun Solaris (5.10), Firefox 3.0.8, Java plug-in 1.6.0_12, Sun Java Desktop System or CDE
    I can not reproduce this behavior using appletviewer, nor can I reproduce it on the Mac (Opera/Firefox/Safari), nor on Windows (Firefox/IE).
    I've crafted some code that shows the behavior:
    FocusApplet.java:
    import javax.swing.JApplet;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.beans.*;
    public class FocusApplet extends JApplet {
      JTextArea infoText;
        Object activeWindow;
        Object focusOwner;
        Object permanentFocusOwner;
           Applet contains two components.
           NORTH: Text field
           CENTER: Info text
           The info text is updated whenever the following
           KeyboardFocusManager properties change:
              activeWindow
           focusOwner
           permanentFocusOwner
      public void init(){
          JTextField tf = new JTextField("Type here");
          infoText = new JTextArea();
          infoText.setEditable(false);
          infoText.setLineWrap(true);
          infoText.setWrapStyleWord(true);
          infoText.setBorder(new EtchedBorder());
          this.add(infoText, BorderLayout.CENTER);
          this.add(tf, BorderLayout.NORTH);
          KeyboardFocusManager focusManager =
           KeyboardFocusManager.getCurrentKeyboardFocusManager();
          activeWindow=focusManager.getActiveWindow();
          permanentFocusOwner=focusManager.getPermanentFocusOwner() ;
          focusOwner=focusManager.getFocusOwner() ;
          updateText();
          focusManager.addPropertyChangeListener(
           new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent e) {
              String prop = e.getPropertyName();
              if ("focusOwner".equals(prop)) {
                  focusOwner = e.getNewValue();
                  updateText();
              } else if ("permanentFocusOwner".equals(prop)) {
                  permanentFocusOwner = e.getNewValue();
                  updateText();
              } else if ("activeWindow".equals(prop)) {
                  activeWindow = e.getNewValue();
                  updateText();
          // Create non-modal dialog
          JDialog jdl = new JDialog((Frame)null,"Extra dialog",
                        false/*modal*/);
          jdl.setSize (300,550);
          jdl.setVisible(true);
        public void updateText() {
         infoText.setText("Active window: "+getName(activeWindow)+
              "\nFocus owner: "+getName(focusOwner)+
            "\nPermanent focus owner: "+getName(permanentFocusOwner));
        public String getName(Object obj) {
         return (obj==null) ? "null" : obj.getClass().getName();
    }Applet HTML:
    <applet code="FocusApplet.class" width="400" height="400"></applet>When I run this applet, I can click on the text field ("Type here") and enter text. Then, I switch between the empty dialog box and the applet using the window manager. (I.e., clicking on the dialog, then clicking on the applet.) Sometimes I see the following Keyboard Focus settings when I bring the applet to the front:
    Active window: sun.plugin.viewer.frame.XNetscapeEmbeddedFrame
    Focus owner: javax.swing.JTextField
    Permanent focus owner: javax.swing.JTextField
    In this case, clicking on the text field will allows the user to edit text. Good! However, 10%-50% of the time I get the following settings after I bring the applet to the front:
    Active window: null
    Focus owner: null
    Permanent focus owner: javax.swing.JTextField
    In this case, I can click on the applet, and I can highlight text in the text field, but I can not edit the text. (No carat appears. Bad!) Since there is no keyboard focus owner, the applet appears non-responsive.
    I have a few questions:
    1. Is this a Java plug-in bug? A Firefox bug? Who do I file a bug with, assuming there's not something I'm missing?
    2. Can anyone suggest a workaround?
    Thanks,
    -David-

    I noticed the problem too. Is there any fix or workaround? Friends using Windows say that all is ok.
    Linux x86_64 (Gentoo), Firefox 3.5.1, jre 1.6.0.15.

  • How to detect loss of keyboard focus?

    I’ve got a numeric input field that must be padded with
    leading zeros to exactly 8 digits. The handler to pad the input is
    trivial and calling the handler on various mouse events is equally
    simple, however, I would also like to call the handler when the
    input field looses keyboard focus by tabbing. Apparently, keyDown
    events are not passed for the tab key when auto tabbing is engaged.
    Anyone know if there is an event triggered by loss of focus?

    There is no onBlur event in Lingo (though something like it
    would be a
    useful addition). You'll need to poll for keyboard focus.

  • Dir11 is loosing keyboard focus!

    I have a kiosk application running WITHOUT a mouse. All
    inputs is from the keyboard. The app is autostarting when Windows
    starts.
    After playing a Flash animation and a mpeg2 video (Mpeg adv
    xtra) the application looses keyboard focus, wich result in Windows
    warning sound when you press a key and the key is not sent to the
    application.
    The problem is solved if you click with a mouse, but there is
    no mouse as I mentioned. The problem is NOT solved by <alt>
    <tab>-switching forth and back.
    I know this is an old MX2004 bug, and the work around then
    was to set the document type to "tool". But this is not helping in
    Dir11.
    Anyone hwo has a work around?
    Where to report bugs now a days? Does Adobe care at all?
    (It's not easy to even find the Director support pages!)

    Hi,
    maybe you can use one of the Xtras than can simulate a
    mouseclick?
    Richard
    "stageit ab" <[email protected]> wrote in
    message
    news:ganvvs$2as$[email protected]..
    >I have a kiosk application running WITHOUT a mouse. All
    inputs is
    >from the
    > keyboard. The app is autostarting when Windows starts.
    > After playing a Flash animation and a mpeg2 video (Mpeg
    adv xtra)
    > the
    > application looses keyboard focus, wich result in
    Windows warning
    > sound when
    > you press a key and the key is not sent to the
    application.
    > The problem is solved if you click with a mouse, but
    there is no
    > mouse as I
    > mentioned. The problem is NOT solved by <alt>
    <tab>-switching forth
    > and back.
    >
    > I know this is an old MX2004 bug, and the work around
    then was to
    > set the
    > document type to "tool". But this is not helping in
    Dir11.
    >
    > Anyone hwo has a work around?
    > Where to report bugs now a days? Does Adobe care at all?
    (It's not
    > easy to
    > even find the Director support pages!)
    >
    >
    >

Maybe you are looking for

  • SIGSEGV (0xb)

    Following error is received while running a java application on linux, crashing the jvm # A fatal error has been detected by the Java Runtime Environment: # SIGSEGV (0xb) at pc=0x000000000000003a, pid=7629, tid=140107993413376 # JRE version: 6.0_24-b

  • Problem in fetching row code...

    Hi there, I have a bit of a problem setting up automatic row processing. The Apex processing is causing an error, but I'm not sure what PL/SQL code is being run (obviously, I don't have access to the Apex code) and all I get is the error following: 0

  • I need help in getting my reponses

    I need help in getting my responses back, or I am sending out the form wrong and people aren't getting it. Either way I need help, as I am getting very frustrated.  Thanks Dori

  • How to sing in into icloud? What does it mean error 403?

    How can i sing in into icloud it says error 403 what does it mean? What is the solution for this problem? Waiting for an aswer please!

  • Run SQL statement from APPS

    Hello I have SQL statement with parameters and I want client to run it from APPS. What should I do for this.