MouseEvents and KeyEvents in the same form is not working

Hello!
I'm newbee in java althought i've bee programing for a long time in other languages, C, C++ wich i'm proud of.
Now i land on java and there are a lot of cuestions (nothing that cant be solved by trying and reading).
But today i hitted my head against all posible solutions and nothing (but bad mood) came out.
The code with trouble is this...
public class NewJFrame extends javax.swing.JFrame
    public NewJFrame()
        initComponents();
    private void initComponents() {
        jButton1 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            public void keyReleased(java.awt.event.KeyEvent evt) {
                formKeyReleased(evt);
            public void keyTyped(java.awt.event.KeyEvent evt) {
                formKeyTyped(evt);
        jButton1.setText("jButton1");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
        pack();
    private void formKeyTyped(java.awt.event.KeyEvent evt) {
        Integer i = evt.getKeyCode();
    private void formKeyPressed(java.awt.event.KeyEvent evt) {
        Integer i = evt.getKeyCode();
    private void formKeyReleased(java.awt.event.KeyEvent evt) {
        Integer i = evt.getKeyCode();
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
        Integer i = evt.getButton();
    private javax.swing.JButton jButton1;
}In debug mode i cant listen to mouse events and key events in the same form. Is that normal ?
In case this is normal, how can i surround this "problem" and make it work.
Thanks a lot in ahead.

Thanks for trying to understand whats going on ...
There is my SSCCE
* NewJFrame.java
* Created on 2 de mayo de 2008, 20:32
* @author  edu
public class NewJFrame extends javax.swing.JFrame
    public NewJFrame()
        initComponents();
        setFocusable(true);
        requestFocus();
    private void initComponents() {
        jButton1 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            public void keyReleased(java.awt.event.KeyEvent evt) {
                formKeyReleased(evt);
            public void keyTyped(java.awt.event.KeyEvent evt) {
                formKeyTyped(evt);
        jButton1.setText("jButton1");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jButton1)
                    .addGap(0, 0, Short.MAX_VALUE)))
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jButton1)
                    .addGap(0, 0, Short.MAX_VALUE)))
        pack();
    private void formKeyTyped(java.awt.event.KeyEvent evt) {                             
        setTitle(String.valueOf(evt.getKeyCode()));
    private void formKeyPressed(java.awt.event.KeyEvent evt) {                               
        setTitle(String.valueOf(evt.getKeyCode()));
    private void formKeyReleased(java.awt.event.KeyEvent evt) {                                
        setTitle(String.valueOf(evt.getKeyCode()));
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
        setTitle(String.valueOf(evt.getButton()));
    private javax.swing.JButton jButton1;
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
}It's quite simple, its suposed to show on the windows title the KeyCode (if there is any) or the MouseButton when pressed.
The problem is: it doesnt work... (if i comment out the jButton1 related code, that means that i dont listen to MouseEvents & dont add the MouseAdapter as MouseListner to the form, the KeyEvents are raised and i can listen to them - but there are no MouseEvents - if i run the SSCCE like above i can listen to the MouseEvents, but cant listen to the KeyEvents. Can you tell me why?
Just before posting i realized it was a focus issue ! The button got the focus and got all the events redirected towards him ! I solved it with the code
        jButton1.setFocusable(false);and it finally worked !
Thanks!

Similar Messages

  • Developer 1.6, 2.1 and 6i on the same machine does not work

    I have installed the three versions on the same machine against Oracle 7.3.4 in another node. Each one is installed in a different OracleHome. Version 2.1 and 6i works fine but when I run Forms 1.6 I get a message telling me that it cannot find the fmcus.msb.
    Is trying to find it in the path of the Developer 2.1 and of course it does not work.
    The Oracle Home selector only shows me those corresponding to 2.1 and 6i.
    It is possible some workaround even if running one version at a time.
    Thanks.

    I have installed the three versions on the same machine against Oracle 7.3.4 in another node. Each one is installed in a different OracleHome. Version 2.1 and 6i works fine but when I run Forms 1.6 I get a message telling me that it cannot find the fmcus.msb.
    Is trying to find it in the path of the Developer 2.1 and of course it does not work.
    The Oracle Home selector only shows me those corresponding to 2.1 and 6i.
    It is possible some workaround even if running one version at a time.
    Thanks.

  • Latin1 and latin2 in the same form with a unicode system

    We're migrating from 4.6B to 6.0, and from non-unicode to unicode. we need to print latin1 and latin2 in the same form.
    How we can do? We try with unicode-device type: in the preview seem to be good, but then (of course) if printers don't supports unicode special caracthers are bad.
    I read about a cascading fonts...
    Have you had a solution?
    tnx
    Lorenzo

    Yes.. Solved. Now latin1 and latin2 are printed on the same form, without changing any sapscript.
    But now, the layout of the print are slightly moved down, so it's missing a little bit of document, as the printer as mistaked margins. The same printer, on the same form, with another device type print correctly (except, of course, the problem on latin2).
    Tnx in advance for your solution

  • In outlook 2013 Add-In, Adding dynamic menu to splitButton idMso="DialMenu" is working and the same code is not working in outlook 2010 Add-In.

    In outlook 2013 Add-In, Adding dynamic menu to <splitButton idMso="DialMenu"> is working and the same code is not working in outlook
    2010 Add-In. please let me know, if i am missing something. Below is the xml and screen shot
    <contextMenu idMso="ContextMenuFlaggedContactItem">
     <splitButton idMso="DialMenu">
              <menu>
                <dynamicMenu id="CallContactwithFreedomvoice
    " label="CallContactwithFreedomvoice" 
                            getContent="OnGetContenttest"                           insertAfterMso="Call"/> 
            </menu>       </splitButton>    </contextMenu> 

    Hi Narasimha prasad2,
    Based on the description, the context menu for the flagged contact doen't work in Outlook. I am tring to rerpoduce this issue however failed.
    I suggest that you check the state of the add-in first to see wether the add-in was loaded successfully.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I am unable to open any app on my iphone. While i'm trying to open an app, it just shakes the screen and it does not get open and remains in the  same page. It worked fine until I charged the phone in my laptop. Please can anyone help me to recover it?

    I am not able to open any app on my iphone. While i'm trying to open an app it just shake the screen and it does not open and remains in the same screen. It worked fine until I charged the phone this evening. After that suddenly I'm facing this. Please can anyone help me to recover this issue? pls!

    This is covered in the basics section.
    A restore loses nothing.
    A restore does.  If you are using the iphone as designed, then everything should be on your computer.

  • HT4061 My phone can't turned on. I tried to press the home button and main button at the same time, but not working. what should I do?

    Iphone 4s can't turned on, goes total black. Tried to press button and main button at the same time, but not working. what should I do?

    recovery mode
    open itunes on computer
    plug cable into computer not iOS device
    turn phone off
    hold home button and plug cable into phone.  do not release home button until an itunes graphic appears on device.
    look to computer should have message about recovery mode click ok and restore
    Peace, Clyde
    if u need an article see
    http://support.apple.com/kb/HT1808

  • When you install Premiere Pro as the admin on an iMac the audio functionalities work well but a second admin account on the same machine does not work. What can I do to fix this?

    When you install Premiere Pro as the admin on an iMac the audio functionalities work well but a second admin account on the same machine does not work. What can I do to fix this?

    It is a bad idea to hack computer passwords when you don't own the computer
    Good luck with the school and the parents.

  • Last night I bought Adobe XI Pro and this morning the serial number does not work.

    Last night I bought Adobe XI Pro and this morning the serial number does not work.  [removed by moderator]

    You need to contact Adobe Support either by chat or via phone when you have serial number and activation issues.
    Here are some links to help make contact:
    http://www.adobe.com/support/chat/ivrchat.html
    http://www.adobe.com/support/download-install/supportinfo/

  • When importing clips to iMovie11 the audio is missing. I have been able to successfully to this in the past and all of the sudden it is not working. Any help to solve the problem would be appreciated.

    When importing clips to iMovie11 the audio is missing. I have been able to successfully to this in the past and all of the sudden it is not working. Any help to solve the problem would be appreciated.
    Thank you for your help!

    Download/install an app is a know possible solution.
    3. Install another app from the App Store
    If all user-installed apps are not launching, it could be an Apple ID authorization issue. Download and install an app that isn't already installed on your device to reset this information.
    Note: If you have installed apps using multiple Apple ID accounts, you may need to perform this step for each account.
    Above from Apple's :
    iOS: Troubleshooting applications purchased from the App Store

  • I am using firefox 3.6.17 i upgraded it to 4.1.but it does not work properly sometimes it opens every website and most of the time it does not work . so what is the problem please help . thank you

    i am using firefox 3.6.17 i upgraded it to 4.1.but it does not work properly sometimes it opens every website and most of the time it does not work . so what is the problem please help . thank you

    Did you check your security software (firewall)?
    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process.
    See:
    * [[Server not found]]
    * [[Firewalls]]

  • HT201321 Numbers pad 4 5 6 and the up down arrow key quit working. I swithched keybouards (Both are Apple, and still have the same problem, its not hardware.)

    The 4 5 6 keys and the up down arrows do not work.
    I had the Cap C off for a While Had hit some key command
    that shut it off so I got a new keyboard and it did the same.
    HAs anyone had this problem

    Does the problem happen if you reboot the system into Safe Mode by holding the Shift key at startup?
    Additionally, does the problem happen if you create a new user account in the Users & Groups system preferences and log into that?

  • No access with SP Designer 2010 after change to FBA and Windows at the same time - Does this work with SP 2013

    Hi All,
         It seems you can't use SharePoint Designer 2010 to open a site if you have both forms and Windows Auth selected.
    Is there any way around this if i want to use the 2 at the same time?
    How does this work with SharePoint 2013 as i would be doing some migrations?
    Cheers in Advance

    Hi,
    As I understand, you encountered the issue after you selected both FBA and Windows Authentication at the same time.
    As I test, I can open the SharePoint 2010 site using FBA and Windows Authentication by SharePoint designer 2010. When you open the site first,
    you will get a dropdown menu where you can choose between the 2 authentication mechanisms.
    After you choose one of them, you can open the site.
    https://onedrive.live.com/redir?resid=40B702A9FB117DD!136&authkey=!ABtMg5n3OtPakCg&v=3&ithint=photo%2cPNG
    When I open the SharePoint 2013 site using FBA and Windows Authentication by SharePoint designer 2013, I also get
    a dropdown menu where I can choose between the 2 authentication mechanisms. I can open the site after I choose one of them.
    So I think there are some other reasons to cause the issue.  
    Check these things below:
    1. Check if you have the permission to open the site in SharePoint designer (Site Permission > Permission Level in ribbon > Click the permission you belongs to > Ensure Use Remote Interfaces is selected).
    2. Check if you have enabled the SharePoint designer to open the SharePoint site. (Select the web application hosting the site collection using the FBA and windows authentication >Central Administration website > General Application
    Settings > SharePoint Designer > ensure Enable SharePoint Designer
     is selected).
    3. Is there any error when you open the site in SharePoint Designer? If there are any errors, could you please provide it here for further research?
    More references:
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/2a3c022c-f924-4b38-be02-5c5ac7a2927e/cannot-open-sharepoint-site-using-sharepoint-designer-2010-get-a-popup-with-4-possible-causes?forum=sharepointgeneralprevious
    https://social.msdn.microsoft.com/Forums/office/en-US/19628c53-fde2-44b0-806c-64f67263c931/cant-open-sharepoint-site-with-sharepoint-designer-2010?forum=sharepointcustomizationprevious
    Best regards
    Sara Fan
    TechNet Community Support

  • Two server sockets on the same machine, one not working.

    Dear forum users.
    I'm currently having a problem with running two server sockets on the same computer.
    It gives no exceptions or anything, just that if i connect with another machine, the last serversocket that started,
    will not accept connections..
    Scenario:
    Computer 1: Main server.
    Computer 1: Game server.
    Computer 2: Client
    Computer 2 connects first to the main server (lets say port 13371)
    Then connects to game server (port 6112).
    Computer 2 failes to connect to the Game server for some reason.
    But if i open a client at Computer 1, connects to main server, and then game server, it
    works fine.
    And if I put computer 2 as a Game server,
    then everything works fine.
    Working scenario:
    Computer 1: Main server.
    Computer 2: Game server
    Computer 2: Client
    Computer 1: Client
    Now, however many that wants to connect to game server, works.
    I have gone through the code 100 times now it feels like. And still dont see why this happends.
    Anyone know if it is "working as intended"? Or just me doing something completely wrong that i cant see myself?
    Sorry for not posting code, its too much code to post.

    Oh, sorry.
    TCPServer:
    protected ServerSocket serverSocket;
    public abstract void processConnection(Socket client);
        public void listen() {
            try {
                report("Listening to clients on port: " + portNumber);
                while (serverSocket != null && acceptConnections) {
                    processConnection(serverSocket.accept());
                    report("Client accepted on serverSocket.");
            } catch (SocketException e) {
                report("TCPServer/listenForClients : SocketException.", e);
            } catch (Exception e) {
                report("TCPServer/listenForClients : Unknown Exception.", e);
            cleanUp();
            report("Stopped listening on port: " + portNumber);
        }MainServer extends the TCPServer:
        public void processConnection(Socket client) {
            try {
                MainServer_Client tmp = new MainServer_Client(client, this);
                synchronized (clients) {
                    clients.add(tmp);
                Thread th = new Thread(tmp);
                th.start();
            } catch (Exception e) {
                report("MainServer/processConnection : Unknown Exception", e);
        }GameServer extends TCPServer
        public void processConnection(Socket client) {
            try {
                client.setTcpNoDelay(true);
                GameServer_ServerClient tmp = new GameServer_ServerClient(client, this);
                synchronized(clients) {
                    clients.add(tmp);
                Thread th = new Thread(tmp);
                th.start();
            } catch(Exception e) {
                report("GameServer_Host/processConnection : Unknown Exception",e);
                e.printStackTrace();
        }Edited by: Lgeee on Apr 30, 2010 2:57 AM

  • Action link URL calling from another screen from the same web server not work

    Hi there,
    I have an action link URL calling from another screen from the same web server, used the following syntax:
    /analytics/saw.dll?Go&path=.....
    But it is not working, when open the page, it shows error message
              Oops! Google Chrome could not find analytics
    Any help? Thanks!
    Ling

    That's a +1 from me... same issue and yes, isn't inelegant or a shortcoming for some might be the cause of boldness as they rip their hair off their head so thanks in advance for keeping the refinement of the magic potions making the EA secret magic sauce... which may help stop hairloss
    Cheers!
    tfbkny

  • JRE Uninstall string for v7 all the same - but do not work

    We have multiple Windows 7 machines running v7u1 thru v7u10.
    I found the uninstall string and was able to run MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83217010FF} on my own machine to remove the software successfully.
    In looking at u6,u7,u9 and u11 installations, I noticed the Uninstall Strings are exactly the same. But when ran on those machines, the system states "This action is only valid for products that are currently installed".
    However, I can remove the version from the Control Panel.
    So what are the correct uninstall strings for v7u1 thru v7u11?

    All of our users are local admins and tend to install whatever. This leads to a messy environment and we don't always know which version of Java is installed. So, to address that, I created a small script that scours 'HKLM\software\microsoft\windows\currentversion\uninstall' for Java entries, reads the uninstall string then runs the reported uninstall string. The assumption here is that the uninstall string will be an MSI command. (All the machines & versions of Java used the same format.)
    This is a Windows 7 Enterprise (32-bit) environment, but the script also works on 64-bit installations of Windows 7 Enterprise.
    I've tested this with 7u11 and went as far back as 6u21. It should work with just about any version that uses MSI for uninstalling.
    @echo off
    setlocal enabledelayedexpansion
    echo. & echo Checking for Obsolete Versions of Java...
    for /f "usebackq tokens=*" %%a in (`reg query HKLM\software\microsoft\windows\currentversion\uninstall`) do (
         rem echo a is %%a
         for /f "usebackq tokens=2*" %%b in (`reg query "%%a" /v DisplayName 2^>nul ^| find /i "java"`) do (
              rem echo b is %%b
              rem echo c is %%c
              for /f "usebackq tokens=3,4" %%d in (`reg query "%%a" /v UninstallString 2^>nul`) do (
                   echo.     Removing %%c
                   rem echo d is %%d
                   rem echo e is %%e
                   set uninstallcmd=%%e
                   set uninstallcmd=!uninstallcmd:^/I=^/X!
                   rem %%d %%e /qb-
                   %%d !uninstallcmd! /qb-
    :end
    endlocal
    Standard Dislaimer:*
    Neither I nor the respective owners and/or maintainers of Oracle make representations about the suitability of this software for any purpose. This material is provided "as is", with absolutely no warranty of the attached items whatsoever, whether express, implied, or statutory, including, but not limited to, any warranty of merchantability or fitness for a particular purpose or any warranty that the contents of the item will be error-free. Any use is at your own risk. Blah blah blah.

Maybe you are looking for

  • Can't open calendar attachments in iOS 5

    Hi there, We've recently upgraded 70 iPad 2's to iOS 5 and we're very happy with all of the new goodies. One of the new features in iOS 5 is that you allegedly can open attachments in the calendar. We cannot seem to get this to work. Any idea's?  We

  • What does RSDDS_AGGREGATES_MAINTAIN do?

    Hi i searched different forums topics but i am still confused that what does RSDDS_AGGREGATES_MAINTAIN.  report do ? If i execute this report what happens? If i have to schedule this Report execution for Daily purpose then HOW TO SCHEDULE IT DAILY ??

  • Error -3221 - please help

    Can anyone point me in the right direction for solving this error? Having bought a pc and loaded up I-tunes before i was connected to broadband I am very dissapointed to find out that now I am on broadband.. every time I go into I-tunes and try to co

  • Wrong Work center picking up Time sheet

    Hi Scenario is as follows: Earlier Employee has HR assignment to one Work center 1 -WC1 Later, Employee was Assigned to Work center 2- WC2 Problem: When booking time sheet in CAT2 ,  for service order, WC1 was picking up, even though in Service order

  • What happened to linking a web address to text?

    Why can't I link a web address to text or an image in Thunderbird anymore?