Set default Button and provide a KeyEvent to a component with focus !!!

What is to do ???
I have following program:
public class DefaultButton extends Frame implements ActionListener
     private Button close;
     public DefaultButton()
          super("Default-Button");
          setLayout(null);
          setSize(400, 200);
          setLocation(150, 100);
          setBackground(Color.lightGray);
          addWindowListener(new WindowAdapter()
               public void windowClosing(WindowEvent e)
                    setVisible(false);
                    dispose();
                    System.exit(0);
          // CloseButton
          close = new Button("Close");
          close.addActionListener(this);
          close.setVisible(true);
          close.setSize(100, 30);
          close.setLocation(290, 160);
          add(close);
          setVisible(true);
     public void actionPerformed(ActionEvent e)
          String cmd = e.getActionCommand();
          if (cmd.equals("Close"))
               setVisible(false);
               dispose();
               System.exit(0);
     public static void main(String [] args)
          DefaultButton wnd = new DefaultButton();
}If I click on "Close"-button, the window will be closed. But, if the button "Close" has focus, it schold be possibile to close the window with a press on the Enter-Key? How to do it? How can I provide an KeyEvent to button "Close"?
Tanks for any help.

Hi pitalica!
It is possible using KeyListener:
public class DefaultButton extends Frame implements ActionListener, KeyListener {
close.addKeyListener(this);
public void keyPressed(KeyEvent e) {
if ((e.getSource() instanceof Button)
&& (((Button) e.getSource()).getActionCommand == "Close")) {
int kc = e.getKeyCode();
if (kc == KeyEvent.VK_ENTER) {
performs any action
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
I hope it helps.

Similar Messages

  • Menu Actions and the Component with Focus

    Can a menu selection (like cut, copy and paste) be sent to the component with focus without me having to track and store which component had focus last.
    For instance: textfields support cut, copy and paste by themselves (Ctrl-C and so forth), but what is the easiest way to do the same with menus. Do i really have to track the focus at all times and mess around with Transferables and Clipboards and stuff?

    Checkout this forum. It seems like there is an answer. You don't really need to create another class like this, just extend TextAction:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=124465

  • How to set default value and bg color of cross tab cell?

    Hi all
    Which way can I set default value and background color for a crosstab cell where there are no any data?
    I try to pass it in following way
    if isnull(CurrentFieldValue) then
    But is has no effect.

    Hi,
    If your field is numeric
    if currentfieldvalue =0 then cryellow else crnocolor
    if the field is numeric but you don't see the 0 check check if : Suppress if zero is ticked in the Number format tab.
    Regards

  • How to set default currency and Country in R12 financial modules

    Hi all,
    How to set default currency and Country in R12 financial modules (AR,AP,GL,FA,CE) becuase I found some default settings are shown "USD" & "United States" such as create AR Customer, the Country is shown the default "United States"....
    Can anybody advise ?
    Thanks & Regards,

    Hi,
    Change the below profile for the user to a territory different than the US :
    In System Administrator, navigate to Profiles -> System.
    Select Site, Application, and Responsibility.
    Profile options:
    Default Country
    HZ: Reference Territory
    ICX: Territory
    Regards,
    Raju.

  • How do you set default fonts and default text box sizes on bound form fields?

    I am using an existing PDF as a template to build my form in designer.
    I am dragging my objects from the schema window to the form and when I drop it on the form it is way too big - so for every field I do this with I am left to resize and reset the font to every bound object i drop on the page!
    Is there a way to set the default font and the default dimensions of the bound text boxes I am droping on the PDF form page?
    Thanks to anyone who can help!

    iWork '09 DVD set (containing Pages '09 v4.0, Numbers '09 v2.0, and Keynote '09 v5.0) is available from Amazon for USD $20. Apple no longer provides retail store, or OS X App Store downloads. You will need to apply the Apple iWork 9.3 updater afterwards to bring these applications to their n.3 (e.g. Pages '09 v4.3) last versions. You will have an /Applications/iWork '09 folder afterwards.
    I would also launch /Applications/Utilities/Disk Utilities, select your boot drive, and verify/repair permissions — just to be on the safe side for the newly added iWork '09 applicaitons.

  • How to set default view and commands

    I have Acrobat Standard 9, and I wish to set the default for opening files to a full page view with one-page-at-a-time scrolling.  I routinely open many PDF files and have to scroll through the entire document.
    I managed to get the full page view to work, but not the full page scrolling .  Currently, when I open the document, the mouse wheel scrolls the document continuously several lines at a time.  What I want is for the mouse wheel to scroll the document one full page at a time (page up/page down).  I can manually set this by selecting the "Full Page" button on the tool bar (the one with the four arrows), however this is another step I have to perform each time I open a document.
    Is there any way to set the full-page scroll by default?

    Thank you for your help with this.
    Although I can not fix the default view, changing the document properties at least allows me to regulate how it opens the next time.  (Almost as good).
    If anyone from Adobe reads this, a tip for the next version: Please include a setting that would include a forced default view.

  • Setting default button in JInternalFrame

    hi
    i had JInternalFrame screen which was added to an MDI Frame. when i am invoking my JInternalFrame screen from main menu, the default button is not working.
    i have coded like this in JInternalFrame screen:
    this.getRootPane().setDefaultButton(buttonOk);
    can anybody pls help me regarding this?
    thanx
    sarabh.

    try this
    getRootPane().setDefaultButton(btnOK);
          FocusAdapter resetDefaultButton = new FocusAdapter() {
          public void focusGained(FocusEvent e) {
             JButton button = (JButton) e.getSource();
             getRootPane().setDefaultButton(button);
          public void focusLost(FocusEvent e) {
             getRootPane().setDefaultButton(btnOK);
          };he default button can be set by using: getRootPane().setDefaultButton( button );
    However, the metal LAF and Windows LAF work differently once the default button has been set:
    a) Metal - the default button never changes, even when another button gains focus.
    b) Windows - when another button gains focus it becomes the default button. When you tab off this button, the original default button is never reset.
    Hope this helps
    Raheel

  • How to set default button when press "Enter"

    Hi,
    I have a form and it has only one button (Submit). When I press "Enter", it can submit the form and do the action. However, when I add another button (Normal button, not submit), it cannot perform submit action directly when I press "Enter".
    If we press "Enter" and the form can submit automatically, it is more user-friendly than without this feature. Therefore, may I know the method of set the default button when users press "Enter"?

    At first I thought the order of the form controls might matter.  When I run this code:
    <cfdump var="#GetTickCount()#">
    <form action="TestCfgrid.cfm" method="post">
    <input name="x" type="text" />
    <input type="button" value="x" />
    <input type="submit" />
    </form>
    While I am in the text box, if I press the enter key the form submits.  I originally tried it with the submit and button inputs in the opposite order.
    Note that the enter button will not submit the form if you are in a select control (aka dropdown) or a textarea or if your focus is not on a form element.  That's the default behaviour.  If you want to override that, you'll have to write some javascript.

  • Is it possible to set default path and filename to the upload UI element  ?

    Hello All,
       Can some advise on if its possible to set a default path and filename to the upload ui element ? I will like to set a default path and filename to be uploaded to the upload UI. The user will then have the option of using that path or clicking on the browse to set another location.
      Any suggestions or advise ? Thank you very much.
    from
    Kwok Wei

    Hello VS,
      So to confirm, from your opinion, you feel that its not possible to have my upload UI elememt to be displyed on the screen with the path and filename preloaded ?
    Btw, do you have an email that I can reach you at ?
    from
    Kwok Wei

  • How to set default Header and Footer properties for PDF

    Hi,
    Currently we are manually setting the 'PDF and Print Control' properties for each and every dashboard. We understand that print pdf properties are controlled by pdfstyle.fst file under $SAROOTDIR\web\app\res\s_oracle10\b_mozilla_4 but don't have the exact property names to include in header and footer section.
    By default, we want to include company logo, the saved name of the report/dashboard tab and created time in the header. And page# in the footer.
    Where can we set these and what properties names should be used in order for these to be set for every new request/dashboard that is created.
    Thanks and Regards

    Hi,
    I created one request with logo in the header an page in the footer etc. and called StyleSheet. After you can import this formats by each request.
    You can do this in compound layout.
    Regards,
    Stefan

  • How to set default color and font?

    Where do I set a default font and color for my outgoing mail? I looked in the preferences but when you change it there, it changes it for all emails, incoming and out going. Isn't there a way to have different fonts for the outgoing than for the incoming??
    thanks for your time,
    Michelle

    I'm glad that other people have had this problem too. I've spent hours on the web trying to find how to select the default composing font colour. I find it incredible that with all the options available in Mail and other mail applications that Apple haven't included this most basic of requirements. It would be lovely if someone from Apple would let us know why this has been left out and if they are going to put it in VERY soon, perhaps as a software update? Mac's still rule though :o)

  • How to set default encoding and charsets for jsp and servlets.

    Hi,
    Is there any possibility to set default encoding or charset for jsps and servlest (for both request and response)?
    For example in Weblogic such parameters can be set in weblogic specific configuration files (weblogic.xml).
    Thanks in advance.

    Hi,
    I created one request with logo in the header an page in the footer etc. and called StyleSheet. After you can import this formats by each request.
    You can do this in compound layout.
    Regards,
    Stefan

  • Set default fill and stroke from start up?

    Hello, would it be possible to set no fill and 1px black stroke as the default fill when I start up illustrator?

    Yes. Just change the Default Graphic Style in whatever New Document Profile you use most. You can do that by making an object with the attributes you want and Option(Alt)-dragging onto the left most Graphic Style and save the file.

  • Set default Skin and Layout for all users

    Hi all,
    Im using UCM 10GR3 and i must set an default skin and layout for all users.
    Into General Configurations Field > System Variables i set
    LMDefaultSkin=MySkin
    LMDefaultLayout=MyLayout
    But this didnt work. Anybody have a clue?
    My skin is working fine but i have to change via My Profile.
    Best Regards
    Daniel

    only new users.
    According to metalink, each one of these will overwrite existing user settings.
    XuiSearchTemplate=slim
    XuiSearchTemplate=dam
    XuiSearchTemplate=myview
    XuiSearchTemplate=none

  • I have just got new ipad3 , iTunes has stopped working on my pc so I used my friends pc to set up the iPad . Problem is that when I go into iTunes ,my friends apple ID is the default  ID and I can't get into iTunes with my own ID? How can I change default

    How to change apple ID on newly set up iPad ? Used my friends pc as iTunes had stopped working on mine and now his apple ID is showing  as the default ID for iTunes and I can't get into my iTunes account ?? iCloud is fine , just iTunes that I can't seem to change defiant user id.

    Settings>Store>Apple ID. Tap his ID and sign out. Sign in with your ID. If you are in iOS 6 it is Settings>iTunes & App Stores>Apple ID.

Maybe you are looking for

  • Facebook and YouTube app connection

    How do I reconnect the Facebook and YouTube apps to my internet, which is working fine, on my iPad air. The apps work fine on my 5c, but only recently started having network and connection issues.

  • Windows 8, asked to Scan and Fix

    Hi All, My iPod Classic (160GB) lives in my car, connected to a Parrot handsfree kit.  Today it stopped playing music and when I tried to access the device on the Parrot kit it gave a message saying that the software or device was not supported.  A f

  • Capturing Video 8 via Canopus SDVC-300

    I am trying to capture some old Video 8 material. I'm using a Canopus ADVC-300 video converter to convert the analog video to DV. The have the Firewire output of the ADVC-300 connected to the Firewire input on my Mac. I have FCP set to: NTSC/DV 48 kH

  • How can I retrieve a song from a album I pre-ordered?

    I pre-order a new album, and one of the songs came out. It says it purchased, but it's is not in my music library.

  • System-call init-text

    Could you please explain this system-call. What does this below call really does? system-call init-text l_text using l_textkey program l_progname Thanks Prem