KeyBindings: Multiple key selections for actionPerformed in one methdo

I'm making a program where I have several objects that respond differently when different buttons are pressed. I'd like to use key bindings without using anonymous or inner classes as per my preference (I think the code is cleaner and easier to read and understand), so I'd like to find a way to determine which key was pressed in which object. I have an SSCCE here with some psueudocode that is an attempt to explain what I'm trying to do.
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;
public class SSCCE extends AbstractAction
     private JPanel p = new JPanel();
     private JTextField t[] = {new JTextField(10),new JTextField(10)};
     public SSCCE()
          JFrame f = new JFrame("SSCCE");
          p.add(t[0]);
          p.add(t[1]);
          p.getActionMap().put(p.getInputMap().get(KeyStroke.getKeyStroke("F1")), this);
          p.getActionMap().put(p.getInputMap().get(KeyStroke.getKeyStroke("F2")), this);
          p.getActionMap().put(p.getInputMap().get(KeyStroke.getKeyStroke("F3")), this);
          f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          f.setSize(300,100);
          f.setLocationRelativeTo(null);
          f.add(p);
          f.setVisible(true);
     @Override
     public void actionPerformed(ActionEvent arg0)
          /*if (t[0] has focus when event is fired)
           *     if(F1 is pressed)
           *          //do some code
           *     else if(F2 is pressed)
           *          //do other code
           *     else
           *          //do some code
           *else if(t[1] has focus when event is fired)
           *     if(F1 is pressed)
           *          //do some code
           *     else if(F2 is pressed)
           *          //do some code
           *     else
           *          //do some code
     public static void main(String[] args)
          new SSCCE();
}

How? I just tried that, but it didn't work.
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;
public class SSCCE
     private JPanel p = new JPanel();
     private JTextField t[] = {new JTextField(10),new JTextField(10)};
     public SSCCE()
          JFrame f = new JFrame("SSCCE");
          p.add(t[0]);
          p.add(t[1]);
          t[0].getActionMap().put(t[0].getInputMap().get(KeyStroke.getKeyStroke("F1")), new t0F1());
          t[0].getActionMap().put(t[0].getInputMap().get(KeyStroke.getKeyStroke("F2")), new t0F2());
          t[1].getActionMap().put(t[1].getInputMap().get(KeyStroke.getKeyStroke("F1")), new t1F1());
          t[1].getActionMap().put(t[1].getInputMap().get(KeyStroke.getKeyStroke("F2")), new t1F2());
          f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          f.setSize(300,100);
          f.setLocationRelativeTo(null);
          f.add(p);
          f.setVisible(true);
     public static void main(String[] args)
          new SSCCE();
     public class t0F1 extends AbstractAction
          @Override
          public void actionPerformed(ActionEvent e)
               System.out.println(e.getSource());
     public class t0F2 extends AbstractAction
          @Override
          public void actionPerformed(ActionEvent e)
               System.out.println(e.getSource());
     public class t1F1 extends AbstractAction
          @Override
          public void actionPerformed(ActionEvent e)
               System.out.println(e.getSource());
     public class t1F2 extends AbstractAction
          @Override
          public void actionPerformed(ActionEvent e)
               System.out.println(e.getSource());
}

Similar Messages

  • F-44  ZBAPI MULTIPLE LINE SELECTIONS FOR WEB SERVICES

    HI TO ALL,
              I HAVE WRITTEN ZBAPI FOR POSTING MULTIPLE LINE SELECTIONS FOR TCODE F-44, THE ZBAPI  CONSIST OF BDC PROGRAM, WHICH IS WORKING IN SAP SYSTEM PERFECTLY BUT WHEN I AM USING IT IN WEB SERVICES IT IS THROWING A  ERROR MESSAGE.
                     PLEASE CAN ANY ONE TELL ME DOES THIS PROCESS WILL WORK OR NOT, IF YES HOW IS IT POSSIBLE

    Hi Gabriel,
    Let me try to answer some of your questions:
    1) The "Requires Secure Access" attribute of a resource handler controls whether this handler must be accessed/consumed only over SSL (HTTPS). Oracle Database Cloud Schema Service is only offered over SSL, so this attribute does not have any effect on RESTful services deployed in this environment (because secure access is always required and there is no other way). That said, if you want to access such web service from your own APEX instance, your instance must have Oracle Wallet configured with appropriate SSL certificate.
    2) The URI parameters are not required. If your web service returns data for many entities (for example, list of employees in employees/), you may not need a parameter. If your web service returns data for one specific entity (for example, details of one employee in employees/{id}), you may want to identify that entity with a URI parameter.
    3) You can have many URI parameters, for example: customers/{id}/orders/{order_id}.
    4) Yes, these are the same HTTP methods/verbs you would use from PHP.
    5) If you are trying this POST example from your own APEX instance (not Oracle Database Cloud Schema Service) and you are trying to access a web service over SSL, then it is likely that the Oracle Wallet used by your instance does not include the required SSL certificate(s), or the Oracle Wallet is not configured at all.
    6) I recommend to check RESTful Web Services for the Oracle Database Cloud white paper and Oracle REST Data Services Developers Guide. Oracle REST Data Services is the technology that enables RESTful services in the Oracle Database Cloud Schema Service.
    You can certainly create your own web services in the Oracle Database Cloud Schema Service and consume them from the same environment.
    Vlad

  • Multiple Range Selection for field Material in CS14

    Hi friends ,
    Is it possible to make multiple range selection for material field in tcode CS14 [used to compare primary and secondary BOM] i have made it ZCS14.
    if i make matnr2 to matnr2-low
    but my doubt is it feasible solution
    please through some light on this
    regards
    soorya

    Dear Soorya,
    What's your requirement? is that to compare the Alternative BOM's for multiple materials at the same time?
    If it's going to be for comparing one more alternative for the same material,then it's a good report.
    As per to my knowledge if the report is going to be for a list of materials Alternative BOM's means I dont
    think whether it will be a fast(time wise) report.
    Check & revert back.
    Regards
    Mangalraj.S

  • How to have multiple preference files for Mail on one computer

    I would like to have multiple preference files for Mail on one computer, one copy for each person in the organization. I want everybody to log in as the same user. Is this possible?
    Thanks,
    John Link
    Cube, 450 MHz, 640 MB   Mac OS X (10.3.9)  

    Since the Mail.app preference file (along with all other application preference files for a user account) is stored in that user's Home folder/directory, I don't believe this is possible.

  • Multiple line selection for RRI  in WAD

    Is it possible to select multiple lines from 1 query and do a RRI to the receiver query. Eg : Select multiple POs and then go to PO details query which shows PO details of multiple POs in WAD and both the results shown in the same web report?
    I tried the below solution, but all I get is the display of the entire Master data dump and not the filtered values. Any suggestion?????
    Rao  
    Posts: 135
    Registered: 6/24/04
    Forum Points: 8 
       Re: Multiple line selection for RRI   
    Posted: Feb 4, 2008 2:22 PM    in response to: LAKSHMI HARINDRAN           Reply 
    Yes. You can do this. You create web template with ANALYSIS web item. In the item parameters of ANALYSIS web item, you can set a property, single line or multiple for the runtime selection. Once you do this, you create a button option or context selection menu option to jump target. In the button (RRI button) in the command sequence, the first command should be SET_SELECTION_STATE_BY_BINDING and then, the RRI command to jump to the target. Hope it will help.
    Venny.

    Hi, Do you have any solution on this. please suggest. Thanks

  • Multiple row selection for table element

    Hi,
    I have a requirement where I require to select multiple rows from a table element in a WD for abap application.
    I have defined a node with cardinality and selection set to 1..n.
    The contex node contains 4 fields : emp_name, pernr, manager and position.
    The attributes of the table element for selectionmode is set to 'multi' and 'selectionchangebehaviour' is set to 'auto'.
    I have defined an action on the 'onleadselection' event.
    The code in this method also includes the statement 'lo_el_team_view->set_selected( EXPORTING flag = abap_true ).' 
    When I execute the application only 1 row is highlighted at any one time when I select it. You can select multiple rows by holding down the 'ctrl' key but I want to avoid having to do this. Is there anything I have missed out causing multiple row selections not to be all highlighted.
    Thanks in advance for any assistance.

    Hi raj,
    you can try the following code in the 'onleadselect' event of the table,
    create one attribute ' Flag'  of type WDY_BOOLEAN under the node which has been binded to the table.
    DATA lo_nd_node_tab1 TYPE REF TO if_wd_context_node.
      DATA lo_el_node_tab1 TYPE REF TO if_wd_context_element.
      DATA  lo_elements TYPE wdr_context_element_set.
      DATA  lo_ele_select_new TYPE REF TO if_wd_context_element.
      DATA lv_deselect TYPE wdy_boolean.
      DATA lv_flag TYPE wdy_boolean.
      DATA lv_select TYPE wdy_boolean.
      DATA lv_index TYPE i VALUE 0.
      lo_nd_node_tab1 = wd_context->get_child_node( name = wd_this->wdctx_node_tab1 ).
    get the current selected element
      lo_ele_select_new = wdevent->get_context_element( name = 'NEW_ROW_ELEMENT' ).
      CHECK lo_ele_select_new IS NOT INITIAL.
    check whether it has been selected or not
      CALL METHOD lo_ele_select_new->is_selected
        RECEIVING
          flag = lv_select.
      lo_ele_select_new->get_attribute( EXPORTING name = 'FLAG' IMPORTING value = lv_deselect ).
    check whether element has been previously selected or not,if not, set the flag to select it
    IF lv_select IS NOT INITIAL AND lv_deselect IS INITIAL.
        lo_ele_select_new->set_attribute( name = 'FLAG' value = 'X' ).
    if selected currently and previously then set the flag as false,in order to delect it
      ELSEIF lv_select IS NOT INITIAL AND lv_deselect IS NOT INITIAL..
        lo_ele_select_new->set_attribute( name = 'FLAG' value = ' ' ).
      ENDIF.
      CALL METHOD lo_nd_node_tab1->get_elements
        RECEIVING
          set = lo_elements.
    according to the falg, select and delect the elements
    LOOP AT lo_elements INTO lo_el_node_tab1.
        lo_el_node_tab1->get_attribute( EXPORTING name = 'FLAG' IMPORTING value = lv_flag ).
        IF lv_flag = 'X'.
          lo_el_node_tab1->set_selected( abap_true ).
          lo_nd_node_tab1->set_lead_selection_index( lv_index ).  * this statement deselects the lead selection index*
        ELSE.
          lo_el_node_tab1->set_selected( abap_false ).
          lo_nd_node_tab1->set_lead_selection_index( lv_index ).
        ENDIF.
      ENDLOOP.
    I hope this resolves your problem.
    Thanks,
    krishna

  • Multiple keystrokes selection for a JComboBox in JTable

    Has anyone used multiple keystrokes selection in a JComboBox inside JTable before? I can get it done outside JTable by using: http://javaalmanac.com/egs/javax.swing/combobox_CbMultiKey.html
    Looks like JTable has all kinds of problems to support JComboBox.
    Suggestions?
    Thanks,
    James

    If I read you right, you want to use a multiple keystroke combo box as an editor in a JTable?
    If you create the JComboBox as you would like it and then install it as an editor in the column(s) JTable the editor will work like the JComboBox
    Example:
    //- you would have that keyselection Manager class
    // This key selection manager will handle selections based on multiple keys.
    class MyKeySelectionManager implements JComboBox.KeySelectionManager {    ....    };
    //- Create the JComboBox with the multiple keystroke ability
    //- Create a read-only combobox
    String[] items = {"Ant", "Ape", "Bat", "Boa", "Cat", "Cow"};
    JComboBox cboBox = new JComboBox(items);
    // Install the custom key selection manager
    cboBox.setKeySelectionManager(new MyKeySelectionManager());
    //- combo box editor for the JTable
    DefaultCellEditor cboBoxCellEditor = new DefaultCellEditor(cboBox);
    //- set the editor to the specified COlumn in the JTable - for example the first column (0)
    tcm.getColumn(0).setCellEditor(cboBoxCellEditor); Finally, it may be necessary to to put a KeyPressed listener for the Tab key, and if you enter the column that has the JComboBox:
    1) start the editting
    table.editCellAt(row, col);2) get the editor component and cast it into a JComboBox (in this case)
    Component comp = table.getEditorComponent();
    JComboBox cboComp = (JComboBox) comp;3) give this compent the foucus to do its deed     
    cboComp.requestFocus();Hope this helps!
    dd

  • Multiple row select for table not working..

    Hi Experts,
    I have a table in ABAP Web Dynpro where I have enabled the multiple row select functionality. I can select all and deselect all. I can also select a block of adjacent rows of table by choosing first and last by pressing Shift key.
    But I am not able to select multiple individual records for that table.
    I tried the same thing in different system and it works fine there.
    Please let me know if we are missing some standard plugin or we need to enable this in some settings.
    System where the issue is:
    SAP_APPL: release 600, level 18
    SAP_BASIS: Release 700, level 22
    System where it is working fine:
    SAP_APPL: release 604, level 8
    SAP_BASIS: release 701, level 8
    Regards,
    Anand Kolte

    Hi
    Press CTRL key and Select records, you can select multiple records, continuously or randomly your desired selection.
    Cheers,
    Kris.

  • In prod order multiple batch selection for my raw material /sf possible

    Dear All,
    One of problem I am facing is regarding multiple batch selection .
    Scenario is like this
    Finished prdt _ FMBLD003         
    RAW matl  -      2RCH001
    In prodn order my BOM requirement quantity for 2RCH001 IS 75 kg , I have material available in stock in  three diffrent batches
    0000111   40 kg
    0000112   15 kg
    0000113   30 kg  
    I can select any one batch at a time. Is there any option or possibility available wherein we can select multiple batches .
    or Is there possibility that system should automatically split bom quantity as per the batch quantity available shown below
    40       0000111
    15       0000112
    20       0000113
    I tried but didnt found possible solution.
    Please suggest .
    Edited by: sapitheprabhu on May 3, 2011 7:28 AM
    Edited by: sapitheprabhu on May 3, 2011 7:48 AM

    Dear Prabhu,
    When do batch determination you maintain req qty against to batch number in batch determination co: select batch.
    0000111   40 kg
    0000112   15 kg
    0000113   30 kg
    Jainashu

  • Multiple indesign files for product brochure one data merge file

    I have multiple indesign files for product brochure and there are price changes for various products.
    attached is a screen shot of the folder where all the indesign files are located as you can see each one has been laid out as a spread.
    Rather than opening each individual indesign file to amend prices can i quickly? or is there a way of compliling all documents into one file and quickly updating the price with the data merge file.
    thanks in advance.

    Absolutely not.
    (1)     PDF/VT-1 files must also be PDF/X-4 files. The “create PDF via distillation of PostScript” method precludes this since PostScript supports neither live transparency nor color management.
    (2)     The efficiencies of PDF/VT-1 require use of Forms XOjects and Image XObjects in the PDF file. That requires direct PDF creation that you get from PDF export. This is not available via any route that uses stink'in PostScript as an intermediary.
    (3)     Adobe most strongly endorses PDF creation from InDesign via the export function, not printing to PostScript and distilling. Such PostScript is optimized strictly for printing and not for PDF file creation.
              - Dov

  • Multiple key items for a single data item?

    hi all. In my application multiple key items may have the same data item, such as:
    key data
    1 abcd
    1 abcd
    1 abcd
    2 efg
    2 efg
    but it may lead to a lot of duplicate storage spaces. I can use two dbs by giving each data item an ID, just like:
    db1
    key data
    1 1
    1 1
    1 1
    2 2
    2 2
    db2
    key data
    1 abcd
    2 efg
    is there any other simple solutions? thanks in advance

    Hello,
    This sounds like a data modeling question. I think your solution is reasonable, though you'll get a lot of good ideas and info if you read up on normalization for relational schemas - there's a ton of literature out there. Just do a search for "database normalization".
    Normalization is intended to eliminate redundancy and also avoid various update anomalies.
    Warm regards.
    ashok

  • Restricted key figure for more than one key figure

    hi all
    i want to restrict almost three keyfigures based on the  same posting period. So instead of creating restricted key figures for each key figures can i create a RKF for all the three key figures based on the same posting period.
    Is there any way i can do that.
    thanks and regards
    vijaykumar

    hello Chandra,
    if those are the only 3 keyfigures in the query, you can have posting period restricted to the required period in the filter area( if u dont want to the period to be displayed) or else you can restrict the period in the rows/free chars area too.
    you can restrict the posting period using variable with period value as a user input value.
    If there are other key figures too, then you need to create 3 diffrent restricted key figures restricted for this period.
    thanks,

  • Multiple line selection for RRI

    Is it possible to select multiple lines  from 1 query and do a RRI to the receiver query. Eg : Select multiple POs and then go to PO details query which shows PO details of multiple POs.
    Also when you do a RRI from 1 q to other , does the filter criteria of 2nd query pop up to the user ?
    thanks in advance ,
    LH

    Hi Lakshmi,
    Yes, it is possible to select multiple lines from one query. It means as you said, if you select multiple PO's i.e., Po's belong to a customer. If 10 PO's belong to single customer, then if you select that customer and Goto RRI in the report, you will get the details of all those 10 PO's in the RRI report. This is done in RSBBS tcode>After creating RRI>Assignment details-->Map the required fields of sender to the reciever queries according to the need.
    When you use RRI, the reciver query, i.e., the second query will contain the filter selection as usual in the normal report when executed.
    Hope this helps u...
    Regards,
    KK.

  • Multiple Images - selection for pre loading

    The preload image behaviour supplied within Dreamweaver is fine up to a point, but it inserts javascript files and is a pain to use if, for instance, you have 20 or so images to load. Or maybe I'm just lazy!
    It is possible to preload images using CSS2 (see http://www.thecssninja.com/css/even-better-image-preloading-with-css2 ) and in CSS3 (see http://perishablepress.com/press/2010/01/04/preload-images-css3/ )
    But none of these give you the option to browse to a folder, select a group of images from it and paste the results into the  the code.
    Has anyone found an extension that will do this?

    >>What seems to be happening the first time is the
    image isn't loaded before
    >>the fade is finished, so the image just appears after
    a short pause the
    >>first time.
    As has been said many times in thos forum - use the
    MovieClipLoader class to
    load images, and then use that class' onLoadInit method to do
    things with
    the loaded image. Loading is asynchronous - you _have_ to
    wait until the
    image is done loading before doing a fade.
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • How can i send multiple Key note files attached in one e-mail

    I've problem with mail attachment. I want to send multiple files from keynote as 4 attached in one mail. Anyone know how? Do I've to wasting time send it one by one? Your kind advice will be a lot appreciated. Thank you ;)

    You can only email one file at a time from the app. Unless you can copy and paste all four files into the email, you can't do it in the Mail App either. There is a third party app called Group Email with Attachments that will allow you to do this. You will have to be running iOS 4 to attach documents I believe.
    Message was edited by: Demo

Maybe you are looking for

  • Firefox 4 hangs when I 'send' a reply in Yahoo Mail - freezes computer - didn't happen with 3.5.

    After restarting the computer, firefox offers to restore settings. When I check Sent Items it shows that the message was actually sent even though firefox stopped responding before confirming it.

  • Retreiving system directories in java

    I am want to get the system directories e.g. c:\WINNT etc. How do i retreive it. Otherwise how can I check if the given directory is a system directory?

  • Why is firefox continually blocking valid websites and redirecting?

    Firefox frequently (and annoyingly) blocks trusted sites from loading, sites like Sprint.com, for example. I know of no instance where they have blocked a malicious site and I find this practice annoying. How may I stop this from occurring?

  • Reinstalling and backing up iTunes

    Before I installed iTunes on my computer, I purchased a portable 60GB hard drive thinking I would install all of the iTunes programs as well as my music library on that so that I could keep my computer hard drive clear of clutter. I also thought my m

  • Split one Post OFfice in two parts

    Hi there! I have problems with my Poa, because I'm having problems with I/O. Despite of all, my POA is about 250 GB and I think that it's pretty big. So I have a lot of "batch users" that are receiving a lot of emails with low priority, and I am thin