How can I block the keyboard using the glass pane ?

I have a problem with the GlassPaneDemo from the Java Tutorial in
the
uiswing/components/example-swing
folder.
When the glass pane is visible it blocks the mouse input but the
keyboard input doesn't. For example if the glass pane is visible and
you press the F10 key, the menu will be activated. So the keyboard is
not at all blocked.
Can this problem be fixed ? I mean, to really block the keyboard
when the glass pane is visible.
Here I wrote down the specification written in the
Java Documentation at the setGlassPane method from the
RootPaneContainer interface:
The glassPane is always the first child of the rootPane and the
rootPanes layout manager ensures that it's always as big as the
rootPane. By default it's transparent and not visible. It can be
used to temporarily grab all keyboard and mouse input by adding
listeners and the making it visible. by default it's not visible.
As it may be seen, one says that the keyboard input can be blocked.
HOW ?
In hope that I resolve the problem, I have made some changes such as,
adding a key listener to the glass pane add listening to the keyboard events,
but I failed to fix the problem.
Faithfully yours,
Sarmis

Here is an example that I think will work for you.
Note the consume() call on the event object. I think that is what you're after.
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
public class Comparer extends JFrame implements ActionListener
    private GlassComponent myGlassPane;
    private JTextField myField;
    public Comparer()
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(myField = new JTextField(20));
        setGlassPane(myGlassPane = new GlassComponent());
        JButton theButton = new JButton("Glass");
        theButton.addActionListener(this);
        getContentPane().add(theButton);
        pack();
    public void actionPerformed(ActionEvent anEvent)
        myGlassPane.setVisible(true);       
    public static void main(String[] args)
        new Comparer().setVisible(true);       
class GlassComponent extends JComponent implements AWTEventListener
    Window myParentWindow;
    public GlassComponent()
        super();
        this.setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) );
        setOpaque(false);
        addMouseListener( new MouseAdapter() {} );
    public void setVisible(boolean aVisibleBoolean)
        if(aVisibleBoolean)
            if(this.myParentWindow == null)
                this.myParentWindow = SwingUtilities.windowForComponent(this);
            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
        else
            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
        super.setVisible(aVisibleBoolean);
    public void eventDispatched(AWTEvent anEvent)
        if(anEvent instanceof KeyEvent && anEvent.getSource() instanceof Component)
            if(SwingUtilities.windowForComponent( (Component)anEvent.getSource()) == this.myParentWindow )
                ((KeyEvent)anEvent).consume();
} HTH,
Fredrik

Similar Messages

  • I have two Apple ID, how can I delete one and use the email address associates to the main one?

    I have two Apple ID, how can I delete one and use the email address associates to the main one?

    If you abandon one of the Apple IDs you will also basically be abandoning any content that you have acquired with that Apple ID. Content can only be updated and re-downloaded with the Apple ID that was used to buy it. Apple will not combine the content of Apple IDs and Apple will not transfer the content from one Apple ID to another Apple ID.

  • How can i reformat my harddrive using the recovery disk stored in partition drive?

    hi guys! i need help. i need to reformat my harddrive and i will do this for the first time. however, i was not ablt to make the recovery disk since i purchased the tx2 1275dx laptop last july 2009. what i have is a recovery disk stored in a partition harddrive. how can i reformat my cpmputer using the recovery disk in partition harddrive? my OS is windows vista.  thank you...  

    Hi,
    Shutdown the notebook.  Tap away at f11 as you start to access Recovery Manager which you can then use to reinstall the Operating System.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • Developing a 2 page form, username on the 1st page, password on 2nd how can i force FF to use the username from previous page when it asks to remember acct info?

    I am developing a 2 page signup form, where the person enters their username on the 1st page and password on the 2nd.
    When I test the form, FF asks to remember my password for the site - however it thinks the zipcode (field above the password) is the username on the account.
    I have tried to put their username/email in a hidden field on the 2nd page, just above the password field - and that did not work.
    How can i force FF to use the username from previous page when it asks to remember acct info?

    This website is using autocomplete=off to prevent Firefox from saving and filling the name and password.
    You can remove autocomplete=off with a bookmarklet to make Firefox save names and passwords and other form data.
    *http://kb.mozillazine.org/User_name_and_password_not_remembered

  • Hello! I'm out of the country and all my iWeb information is on my computer at home. Now I need to make changes on the webpage... how can i do that without using the computer i made the page on? Thank you!!

    Hello! I'm out of the country and all my iWeb information is on my computer at home. Now I need to make changes on the webpage... how can i do that without using the computer i made the page on? Thank you!!

    iWeb uses the domain.sites2 files to store its assets.
    You'll find it here :
    ~/Library/Application Support/iWeb/
    where ~ is your Home directory.
    If you take a computer with you, you have to store that file in the same location.
    It's not different from taking documents with you if you want to edit them.
    A solution is to remotely control your computer at home.
    TeamViewer, LogMeIn, Apple Remote Desktop or any VNC application you can use, like "Chicken of the VNC".

  • How can I make Time Machine use the ethernet cable to Time Capsule instead of the wireless connection? Wireless is too slow; has been taking 40 hours to create an initial 142 GB backup.

    How can I make Time Machine use the ethernet cable to Time Capsule instead of the wireless connection? Wireless is too slow; has been taking 40 hours to create an initial 142 GB backup.

    Plug in ethernet .. in the computer.. turn off wireless.

  • How can we publish Labview data using the web

    how can we publish Labview data using the web?
    Dr. Eugene Berman, Moran Kamilyan and Ravit Bar

    [email protected] wrote:
    how can we publish Labview data using the web?
    You could use shared variables and publish them to the network or use data sockets.
    Kudos always welcome for helpful posts

  • How can I add an appoggiatura using the score editor?

    I'm using Logic Pro X to write an ensemble piece and I need to add an appoggiatura, how do I do it?

    Hi
    I'm not sure what your issue is: add extra notes, convert them to Independent Grace notes, and adjust the positions using the Layout tool as needed.
    CCT

  • My mac was stolen, how can i blocked it and recover the info?

    My mac air was stolen, i dont have the icloud id, how can i recover the info and blocked the computer so that the thief canot use it?

    You can't. Change your passwords and cancel any credit cards you may have used while on the computer.
    What To Do If Your iDevice Is Lost Or Stolen
    If you activated Find My Phone before it was lost or stolen, you can track it only if Wi-Fi is enabled on the device. What you cannot do is track your device using a serial number or other identifying number. You cannot expect Apple or anyone else to find your device for you. You cannot recover your loss unless you insure your device for such loss. It is not covered by your warranty.
    If your iPhone, iPod, iPod Touch, or iPad is lost or stolen what do you do? There are things you should have done in advance - before you lost it or it was stolen - and some things to do after the fact. Here are some suggestions:
    This link, Re: Help! I misplaced / lost my iPhone 5 today morning in delta Chelsea hotel downtown an I am not able to track it. Please help!, has some good advice regarding your options when your iDevice is lost or stolen.
      1. Reporting a lost or stolen Apple product
      2. Find my lost iPod Touch
      3. AT&T. Sprint, and Verizon can block stolen phones/tablets
      4. What-To-Do-When-Iphone-Is-Stolen
      5. What to do if your iOS device is lost or stolen
      6. 6 Ways to Track and Recover Your Lost/Stolen iPhone
      7. Find My iPhone
      8. Report Stolen iPad | Stolen Lost Found Online
    It pays to be proactive by following the advice on using Find My Phone before you lose your device:
      1. Find My iPhone
      2. Setup your iDevice on iCloud
      3. OS X Lion/Mountain Lion- About Find My Mac
      4. How To Set Up Free Find Your iPhone (Even on Unsupported Devices)

  • How can I purchase a GIFT using the credit balance in my iTunes account?

    When attepting to gft an app to a friend, the iTunes store is asking for a credit card when I have a rather sizable credit in my iTunes account. ***? I don't want to pay MORE when I already HAVE plenty of money in my account!
    How can I gift using my credit?

    That's a total CROCK!! Now I can't buy my mom a mother's day gift.

  • How can I save multiple links using the "save link as" function?

    I'm trying to save about 300 pdf files. The link to each one is listed ona website. To save each one I'm right clicking on the link, selecting "save link as" and repeat.
    How can I select multiple links and save them?

    Actually you can save multiple page pdf's in elements.
    Try something like this:
    (This is easier if you have the project bin open)
    1. Select the first page
    2. Right click on that page in the project bin and choose Add Blank Page or as many pages as you need.
    3. Use the move tool and drag your pages down into the blank pages in the project bin
    4 Then File>Save As>Acrobat.PDF

  • How can i import into imovie using the camera's built in memory?

    How can I import into imovie from my cannon video camera built in memory.  All that comes up when I connect the USB cable is what is stored on the memory card and it doesn't give me the option to use what is stored on the built in memory

    That is not a feature of iPhoto - suggest to Apple - iPhoto Menu ==> provide iPhoto feedback.
    With the new Photo app later this year the integration between IOS and the Mac will be much greater
    LN

  • How can i get icloud to use the same id as my iphone

    how do I change the the icloud id to the id on my iphone

    Hi sheaney,
    You can change the Apple ID in use on your iPhone using the steps in this article -
    Sign in with a different Apple ID on your iPhone, iPad, or iPod touch - Apple Support
    Thanks for using Apple Support Communities.
    Best,
    Brett L 

  • How can I tell MDT to use the efisys_noprompt.bin as the bootloader used to create the litetouch.iso

    I would like to have an iso file that does not have the "press any key to boot from cd/dvd" prompt. I know how to do this manually but I would like to be able to set this somewhere so that MDT will use it whenever the iso is updated. Is there
    a script file somewhere with the command given to oscdimg that can be edited? 

    It's not so much that I think it's unimportant, as that I think you new to MDT, and may be doing things wrong.
    I can't think of a scenario of why you would want to do this, and I have written on my blog about the dangers of mucking around with the BIOS boot order with respect to USB boot drives. There are too many users who don't understand how the system work, or
    what the ramifications are when you change these settings.
    Sure you can remove the bootfix.bin file on BIOS machines to remove the "press any key to..." prompt from DVD media and the like, however if the BIOS settings are configured for DVD before the Hard Disk, you will keep booting into the Litetouch BOot media,
    which is a *horrible* experience for users. on BIOS machines, for example, I have had much better luck of marking boot partitions as Inactive in order to *FORCE* the DVD to boot (Yes the bootfix.bin file will skip the prompt on the DVD *if* there is not hard
    disk marked active).
    Asking "Why would you want to do that? What are you trying to accomplish?" is a perfectly valid question on a technical alias like this.
    Keith Garner - keithga.wordpress.com

  • How can you detect irregular edges using the IMAQ add on?

    Im currently trying to use the IMAQ add-on for LabView to detect the edges of an irregular image. I have attached the image I am trying to detect the edges of. I have tried using everything in the "locate edges" sub-pannel (i.e.. imaq find edge, imaq find circular edge etc.) but none of them have yielded any favorable results. I think the "IMAQ edge tool 3 IV" might be what im trying to find however I don't understand how to get any usable data out of it.
    Thank you, all comments and help are greatly appreciated. 
    Attachments:
    waveguide.png ‏516 KB

    Hi Dander, 
    I am not sure exactly what types of edges you are trying to acquire, but I used one of the examples from our Example Finder and was able to detect edges on your image.  I will say that with the image that you are using, the edges are not very well defined, so you may not get a 100% accurate measurement.  The example that I was using uses the IMAQ Edge Tool 3 VI and the example can be found by going in LabVIEW to Help>>Find Examples...  From there, you will go to Toolkits and Modules>>Vision>>Functions>>Edge Detection Example.vi.  After that, you will remove the build path function and input a path to the image.  I hope this helps!
    Kim W.
    Applications Engineer
    National Instruments

Maybe you are looking for

  • MiniDVI to VGA for use with other (normal) monitors and televisions?

    Just that... Is it the miniDVI to VGA (as opposed to the miniDVI to DVI) adaptor that I should buy to connect the MacBook to other monitors (to get the extension of the MacBook screen) and televisions (so the MacBook can act as a DVD player)? Oh - al

  • System Preferences not locking

    Everyday I have to go into my Mighty Mouse preferences and change the side buttons to a dashboard-all windows shortcut. Is there a way to lock my system preferences? Am I not exiting the system preferences window properly? The dashboard shortcut stuc

  • Save and display the content

    Hello Experts, I have created an XML form to capture the data from the End User and created a HTML file to display the form and integrated this to an iView. Now, I have to capture the data from the XML form and display it in another page. Can you ple

  • Need to list phone contacts by last name alphabetically

     How can I view them in the DroidX by last name, alphabetically?  They are currently listed by first name alphabetically. Thanks much, JW

  • [Android][Music] Permanet Sort by option

    So, every time i go into my playlist on my phone, i constantly have tap, Sort By -> Recently Added so i can hear the latest songs i have added to my playlists. The one thig that really frustrates me and many other users is the the fact that i have to