How to reach Combobox Items via Key pressed (Java5)

Hallo all,
I have a question. I have a JCombobox field and assume that it has its items like (Apple, Banana, Pear). How can I manage to jump into Pear item by pressing P in that combobox?

I am sorry I was wrong. I had to tell that my Combobox value is in my Table and the CellListener doesn't allow to do that. If I am gonna have another Swing problem I am going to send my message to that forum. I don't want to duplicate this question right now. Here is my code.
    public void load() {
        serviceType = data.getMetadata(position).getMetadataValuesSorted().toArray(new MetadataValue[0]);
        String[] metadataValues = new String[serviceType.length];
        for (int i = 0; i < serviceType.length; i++) {
            MetadataValue values = serviceType;
metadataValues[i] = values.getValue();
final TableColumn col2 = table.getColumnModel().getColumn(1);
col2.setCellEditor(new MetadataValueComboBoxEditor(serviceType));
col2.setCellRenderer(new MetadataValueComboBoxRenderer(serviceType));
public class MetadataValueComboBoxRenderer extends JComboBox implements TableCellRenderer {
public MetadataValueComboBoxRenderer(final MetadataValue[] items) {
super(items);
final JComboBox newItems = new JComboBox(items);
setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
if (value != null && value instanceof MetadataValue) {
value = ((MetadataValue) value).getValue();
final String valueString = (String)value;
newItems.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
for (int i = 0; i < items.length; i++) {
if (e.getKeyChar() == valueString.charAt(0)) {
newItems.setSelectedItem(newItems.getComponent(i));
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
registerComponent(this);
public Component getTableCellRendererComponent(final JTable table, final Object value,
final boolean isSelected, final boolean hasFocus, final int row, final int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
} else {
setForeground(table.getForeground());
setBackground(table.getBackground());
setSelectedItem(value);
return this;
public class MetadataValueComboBoxEditor extends DefaultCellEditor {
public MetadataValueComboBoxEditor(final MetadataValue[] items) {
super(new JComboBox(items));
final JComboBox newItems = new JComboBox(items);
registerComponent((JComponent) this.getComponent());
((JComboBox) getComponent()).setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
if (value != null && value instanceof MetadataValue) {
value = ((MetadataValue) value).getValue();
final String valueString = (String)value;
newItems.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
for (int i = 0; i < items.length; i++) {
if (e.getKeyChar() == valueString.charAt(0)) {
newItems.setSelectedItem(newItems.getComponent(i));
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
MetadataValueComboBoxEditor  and MetadataValueComboBoxRenderer inner classes doesn't allow me to select the item via key pressed.
Edited by: NEO1976 on Mar 24, 2008 10:11 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • I called Verizon prior to travelling abroad and asked to turn roaming on. As of today, 4 days later, I have no service. I do not have a landline to call. GlobalServices email does not work... Does anybody know how to reach customer support via email?

    I called Verizon prior to travelling abroad and asked to turn roaming on. As of today, 4 days later, I have no service. I do not have a landline to call support. GlobalServices email does not work... Does anybody know how to reach customer support via email?

        Hi Florence2014
    I'm so sorry your having issues. Unfortunately there isn't an email for global support. The only way way to reach them while traveling is to call them at 908-559-4899.
    JoeL_VZW
    Follow us on Twitter @VZWSupport

  • How to validate Combobox items without expanding the combobox.

    Hi,
    I want to select the combobox item.
    before selecting an item I want to validate whether the item is present in the combobox list.
    while validating the item at for loop the combobox get expanded. 
    I don't want to expand it.
    if (children[index].Name == entryToSelect)
    isExists =
    true;
    break;
    Please share your thoughts.....

    Hi Rosy D,
    I also try to test it in my side.
    As far as I know we could collect all items with ComboBox.ObjectCollection class:
    http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.objectcollection(v=vs.110).aspx
    http://stackoverflow.com/questions/17709363/check-if-user-input-are-in-the-combobox-items
    But it seems that I'm failed to use this method in coded UI tests, so I’m afraid that it has this limitation for this issue.
    We would use the
    GetChildren method,
    but as far as I know, we would expand this control.
    Reference:
    https://social.msdn.microsoft.com/Forums/en-US/6f71fed3-777f-433a-87b0-e4190ff06632/telerik-combobox-returned-as-an-editbox-vs-combobox?forum=vsautotest
    http://stackoverflow.com/questions/18079008/get-all-values-from-a-listbox-using-coded-ui-test-and-select-it
    Best Regards,
    Jack 
    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.

  • How to select combobox item?

    hi,
    i have three panels in cover flow diagram and i have one combobox(three items) beside that coverflow diagram.when i click on the first item then i want to display corresponding panel in cover flow diagram similarly remaining items also.
    plz help me how to di this

    You have to use ViewStack control, as
    <ComboBox />
    <ViewStack selectedIndex={cmbBox.selectedIndex} >
         <Panel 1 />
         <Panel 2 />
         <Panel 3 />
    </ViewStack>
    Hope this will help you.
    Thanks.

  • [JS CS3] How to reach a item in a collection of pageitems whom label is the same ?

    Hi,
    I had a look through the forum and I didn't find any topic on it.
    I have several pageitems whom label is the same : "LogoBox"
    I can have interesting info such as
    b app.activeDocument.pageItems.count("LogoBox")
    So I can know how many iterations I have
    But now I want to apply a function for any instance and then I just don't get success to access element.
    app.activeDocument.pageItems.item("LogoBox")[0] fails
    And don't see any lead ? A idea ?
    Loic

    Hi Robert,
    As I was afraid of that, I have to built a array of pageitems through a loop that analyses any pageitems and its own label.
    that's a pity that the "whose" command doesn't exist and that we can't create collections based on specific datas.
    Loic

  • How to use comboBox as the key to display multiple textInput fields?

    All,
        I am new in Flex and need to help!
    I have selected rows from database and need to display on one comboBox with several textInput fields. The function need to
    1) After the page complete load, the comboBox display the ID (unique key of the row).
        and all fields should fill by the columns with the ID. ( I did it with only one textInput)
    2) When it selects an ID from comboBox, all fields with the ID should change accordingly.
    See attached file.
    Please help.
    Thank you in advance!

    Hi,
    there is an example. All you need to receive your data and
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:XML id="tstData" xmlns="">
    <yueventlists>
    <yueventlist event_id="EMB09">
      <event_id>EMB09</event_id>
      <stvcoll_desc>Albert Einstein College of Med</stvcoll_desc>
      <LOCATION_NAME>Bronx comm center</LOCATION_NAME>
      <LOCATION_ROOM>101</LOCATION_ROOM>
      <LOCATION_CONTACT />
      <PHONE />
      <FAX />
      <STREET />
      <CITY_PROVINCE>New York</CITY_PROVINCE>
      <STATE>NY</STATE>
      <ZIP>10471</ZIP>
      <COUNTRY />
      </yueventlist>
    <yueventlist event_id="EMB10">
      <event_id>EMB10</event_id>
      <stvcoll_desc>Albert Einstein College of Med</stvcoll_desc>
      <LOCATION_NAME>Bronx Red Lobster</LOCATION_NAME>
      <LOCATION_ROOM>102</LOCATION_ROOM>
      <LOCATION_CONTACT />
      <PHONE />
      <FAX />
      <STREET />
      <CITY_PROVINCE>New York</CITY_PROVINCE>
      <STATE>NY</STATE>
      <ZIP>10463</ZIP>
      <COUNTRY />
      </yueventlist>
    <yueventlist event_id="YUD09">
      <event_id>YUD09</event_id>
      <stvcoll_desc>Yeshiva University</stvcoll_desc>
      <LOCATION_NAME>Chelsea Piers Pier Sixty</LOCATION_NAME>
      <LOCATION_ROOM>103</LOCATION_ROOM>
      <LOCATION_CONTACT>0</LOCATION_CONTACT>
      <PHONE>0</PHONE>
      <FAX>0</FAX>
      <STREET>0</STREET>
      <CITY_PROVINCE>New York</CITY_PROVINCE>
      <STATE>NY</STATE>
      <ZIP>10033</ZIP>
      <COUNTRY>0</COUNTRY>
      </yueventlist>
      </yueventlists>
    </mx:XML>
    <mx:Form x="126" y="57">
    <mx:ComboBox id="cmbID" dataProvider="{tstData.*}" labelField="@event_id"></mx:ComboBox>
    <mx:FormItem label="School Name">
    <mx:TextInput id="schoolName" text="{cmbID.selectedItem.stvcoll_desc}"/>
    </mx:FormItem>
    <mx:FormItem label="Location Name">
    <mx:TextInput id="locName" text="{cmbID.selectedItem.LOCATION_NAME}"/>
    </mx:FormItem>
    </mx:Form>
    <!-- and so on... -->
    </mx:Application>

  • Moving a movie clip via key press event question.

    I have a project where I'm trying to move the movie clip: "wally", up and down three levels of a stage.
    However, from the default position I have him move up 145 pixels, and down 120 pixels.
    I want to limit this action to one use, meaning if wally goes up once from his default position he must come back down, and vice versa, if he goes down he must come back up(or stay on that level). Also, if he goes up the 145 pixels, he needs to come back down 145 pixels, likewise if he goes down 120 pixels, he needs to come back up 120 pixels. I might be over-thinking this, as I had to strip it back to the starting code the other day, and am at a loss once more. If this'd be easier performed by moving with keyboard arrows and case statments, let me know, as I'm stumped.
    Starting code:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressHandler1);
    function keyPressHandler1(event:KeyboardEvent):void
              if(event.keyCode==38)
                        wally.y -= 145;
                        else if(event.keyCode==40)
                        wally.y += 120;

    use:
    wally.startY = wally.y;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressHandler1);
    function keyPressHandler1(event:KeyboardEvent):void
              if(event.keyCode==38)
    if(wally.y==wally.startY){
                        wally.y -= 145;
    } else if(wally.y>wally.startY){
    wally.y=wally.startY
                        else if(event.keyCode==40)
    if(wally.y==wally.startY){
                        wally.y += 120;
    } else if(wally.y<wally.startY){
    wally.y=wally.startY;
    p.s. please mark helpful/correct responses.

  • Import alternative item via DTW

    Hi Experts,
    I want to know how to import alternative items via DTW.

    Hi Poonkodi, Sridharan
    In SAP Business One 2007 there is a DI API object for AlternativeItem. Please refer to REFDI.CHM under SDK help folder.
    Kind regards
    Peter Juby

  • Tracking the backspace key press??

    Hi
    I was trying to limit the no. of characters in a JTextField by using Inputverifier class.
    I am able to acheive that. But now the problem is I can't use backspace, arrow keys, etc.
    Since I am tracking key press event. I need to track backspace, arrow keys press too.
    How to track the backspace, arrow keys press?
    Here is my code:
    public class JTextInputVerifier extends InputVerifier
        int maxLength;
        JTextField jtf;
        public JTextInputVerifier(int maxLength) {
            this.maxLength = maxLength;
        public int getTextLimit()
            return maxLength;
        public boolean verify(JComponent c) {
            jtf = (JTextField)c;
            String str = jtf.getText();
            if (str.length() >= maxLength)
                return false;
            return true;
    final JTextInputVerifier inputVerifier = new JTextInputVerifier(10);
            txtCheck.setInputVerifier(inputVerifier);
            KeyListener input = new KeyListener() {
                public void keyTyped(KeyEvent e) {
                    if(!txtCheck.getInputVerifier().verify(txtCheck))
                        txtCheck.setText(txtCheck.getText().substring(0, inputVerifier.getTextLimit()));
                        java.awt.Toolkit.getDefaultToolkit().beep();
                public void keyPressed(KeyEvent e) {
                    throw new UnsupportedOperationException("Not supported yet.");
                public void keyReleased(KeyEvent e) {
                    txtCheck.setText(txtCheck.getText());
            txtCheck.addKeyListener(input);Please suggest some ideas.
    Is there any alternative way to restrict the no. of characters? which won't affect working of backspace, and other keys..?
    Praveen

    Joerg22 wrote:
    You could use a DocumentListenerThis won't work; DocumentListeners get notified after an insertion/deletion occurs. What you need to use is a javax.swing.text.DocumentFilter.

  • Anulate tab key press

    Hi all!
    I have a little problem.
    How can I anulate a tab key press in a TextArea?
    I have this TextArea in an Applet and it's ocurrs only with Microsoft VM. I try with consume() method of KeyEvent but no work.
    Thanks a lot.
    Sergio Mart�n

    Hi arjunravinarayan!
    Thanks for anwer!
    The question is that I want no change in the TextArea content.
    When a press the tab key, a tab space is added to TextArea.
    Sergio Martin

  • How to active menu item by press Alt key

    Hi everyone,
    I don't know how can i active jmenu bar by pressing Alt key first, and press another key ( for exp. press 'F' go to File menu), they are not at the same by holding Alt key.
    Thanks for help in advance.

    I still didn't get it, would you like give me some details.
    How do i make the ALT key select it (but not open it).
    By pressing the "F' key, the "File "menu selected should be opened.

  • How to add an item  in the combobox list at runtime

    i want to add an item to the list of items in the combobox. How can I do this? I tried to use the methods getselecteditem() and getitem() from the actionlistener but no success.
    so after i add an item, the next time when i run that frame, that item should be displayed in the list of items in the combobox. Can anybody help me with this?

    Thanks Encephalophathic.
    Let me explain you the whole design -
    I have a frame having textfields and comboboxes. Now in the combobox, i have added some fields during design time and some i want the user to add at runtime. After the user clicks the Save button, i want the new string if entered in the combobox by the user at runtime to be added in the list of items of the combobox. So the next time when that frame is run, the item added by the user at runtime previously should be there in the list of items displayed in the combobox.
    What I am trying to do in this code at the combobox is if the user enters a new string in the combobox, then if he presses enter key, the value entered in the list of the combobox should be entered in the list of items of the combobox. Actually i m just trying to get the item typed in by the user, so just testing with enter key, but really i want it on the button click. I tried to add the code for adding an item to the combobox in the actionperformed, but i m not able to add it so confused what to do. Please help me with this.
    Here's the whole code for that -
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JComboBox;
    import java.awt.event.ActionListener;
    import javax.swing.JOptionPane;
    import javax.swing.JDialog.*;
    import javax.swing.JComboBox;
    public  class EnterFD implements ActionListener{
      private JFrame frame;
       private JPanel mainpanel,menupanel,userinputpanel,buttonpanel;
       private JMenuBar menubar;
       private JMenu menu,submenu;
       private JMenuItem menuitem;
       private JCheckBoxMenuItem cbmenuitem;
       private JLabel fdnumber;
       private JLabel bankname;
       private JLabel beneficiaryname;
       private JLabel entereddate;
       private JLabel maturitydate;
       private JLabel rateofinterest;
       private JLabel amount;
       private JLabel maturityamount;
       private JTextField fdnumbertxtfield;
       private JComboBox banknamecombobox;
       private JTextField beneficiarynametxtfield;
       private JComboBox entereddatecombobox;
       private JComboBox maturitydatecombobox;
       private JTextField rateofinteresttxtfield;
       private JTextField amounttxtfield;
       private JTextField maturityamounttxtfield;
       private JButton savebutton;
       private JButton clearbutton;
    public EnterFD() {
            initComponents();}
        private final void initComponents(){
            fdnumber = new JLabel("FD Number:");
            bankname = new JLabel("Bank Name:");
            beneficiaryname = new JLabel("Beneficiary Name:");
            entereddate = new JLabel("Entered Date:");
            maturitydate = new JLabel("Maturity Date:");
            rateofinterest = new JLabel("Rate Of Interest:");
            amount = new JLabel("Amount:");
            maturityamount = new JLabel("Maturity Amount:");
            fdnumbertxtfield = new JTextField();
            banknamecombobox = new JComboBox();
            banknamecombobox.addItem("State Bank Of India");
            banknamecombobox.addItem("Bank Of Baroda");
            banknamecombobox.addItem("IDBI Bank");
            banknamecombobox.addItem("ICICI Bank");
            banknamecombobox.addItem("Punjab National Bank");
            banknamecombobox.setEditable(true);
            banknamecombobox.setSelectedIndex(-1);
            banknamecombobox.addKeyListener(new java.awt.event.KeyAdapter() {
                @Override
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    banknamecomboboxKeyTyped(evt);
            banknamecombobox.addKeyListener(new java.awt.event.KeyAdapter() {
                @Override
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    banknamecomboboxKeyReleased(evt);
            beneficiarynametxtfield = new JTextField();
            entereddatecombobox = new JComboBox();
            maturitydatecombobox = new JComboBox();
            rateofinteresttxtfield = new JTextField();
            amounttxtfield = new JTextField();
            maturityamounttxtfield = new JTextField();
            menubar = new JMenuBar();
             menu = new JMenu("File");
             menubar.add(menu);
             menuitem = new JMenuItem("New");
             menu.add(menuitem);
             menuitem.addActionListener(this);
             menuitem = new JMenuItem("Save");
             menu.add(menuitem);
             menuitem.addActionListener(this);
             menuitem = new JMenuItem("Close");
             menu.add(menuitem);
             menuitem.addActionListener(this);
             menuitem = new JMenuItem("Exit");
             menu.add(menuitem);
             menuitem.addActionListener(this);
             menu = new JMenu("Edit");
             menubar.add(menu);
             menuitem = new JMenuItem("View FD");
             menu.add(menuitem);
             menuitem.addActionListener(this);
            mainpanel = new JPanel(new BorderLayout());
            menupanel = new JPanel(new BorderLayout());
            menupanel.add(menubar);
             userinputpanel = new JPanel(new GridLayout(8,2,5,20));
            userinputpanel.setBorder(BorderFactory.createEmptyBorder(50,50,80,80));
            userinputpanel.add(fdnumber);
            userinputpanel.add(fdnumbertxtfield);
            fdnumbertxtfield.setColumns(50);
            userinputpanel.add(bankname);
            userinputpanel.add(banknamecombobox);
            userinputpanel.add(beneficiaryname);
            userinputpanel.add(beneficiarynametxtfield);
            beneficiarynametxtfield.setColumns(50);
            userinputpanel.add(rateofinterest);
            userinputpanel.add(rateofinteresttxtfield);
            rateofinteresttxtfield.setColumns(50);
            userinputpanel.add(amount);
            userinputpanel.add(amounttxtfield);
            amounttxtfield.setColumns(50);
            userinputpanel.add(maturityamount);
            userinputpanel.add(maturityamounttxtfield);
            maturityamounttxtfield.setColumns(50);
            savebutton = new JButton("Save");
            clearbutton = new JButton("Clear");
            JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            buttonpanel.add(savebutton);
            buttonpanel.add(clearbutton);
            savebutton.addActionListener(this);
            clearbutton.addActionListener(this);
            mainpanel.add(menupanel,BorderLayout.NORTH);
            mainpanel.add(userinputpanel,BorderLayout.CENTER);
            mainpanel.add(buttonpanel,BorderLayout.SOUTH);
            frame = new JFrame("Enter FD");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(3000,3000);
            frame.setContentPane(mainpanel);
            frame.pack();
            frame.setVisible(true); }

  • How to get the actual key pressed in a UITextField

    Hi all , now i develop a program on iphone SDK 3.0 GM.
    I have an UITextField (created programmatically) and I have implemented the delegate as well as the UITextFieldTextDidChangeNotification so that I can react to changes in the text values.
    However, I specifically want to know when the user presses the backspace key in the UITextField when there is currently no text in the field. I can't find where I can get a specific notification of the actual key pressed, as opposed to the resulting state of the text. I'm sure there is a way to do this...help?

    I can imagine why you want to do it. I had the same problem myself and managed to circumvent it in a slightly painful way. What I did was to subclass UITextField to create a text field that always had text in it, even when it "seemed" empty. In fact the first character of the text is a space character, and then what follows is the actual text. In this way, your delegate will always get called about a backspace (when it's an attempt to delete the leading space character, obviously you should return NO in the textField: shouldChangeCharactersInRange: replacementString: method). I won't get into the details of exactly how to set everything up, like I said it is kind of elaborate and I wouldn't really recommend it unless you are desperate to have that kind of functionality.

  • How to pass the key pressed in javascript

    I'm asking this question here as I could not find the needed help elsewhere .
    I don't know how to pass the key pressed in the function on OnKeyPress event .
    I'm trying the following :
    <input type="text" name="a" onKeyPress="check();">
    I want to pass the key presses in the check function .
    How to collect the key pressed in the function check ?
    Thanks.

    As I said above, that won't work in Mozilla.
    In fact IMO Netscape/Mozilla javascript event handling has been behind IE since version 4.
    Be that as it may: here is a workaround (for Mozilla): It seems you have to assign the onkeypress event for it rather than declaring it as part of the textfield.
    Of the two textfields on this form, both work in IE, and only the first one will work properly in Mozilla. I left it in just to demonstrate the difference.
    And a couple of links for ya
    javascript forum: http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=3
    Keypress events: http://www.din.or.jp/~hagi3/JavaScript/JSTips/Mozilla/Samples/KeyEvent.htm
    <html>
    <head>
    <script language="javascript" >
    <!--
    function check(evnt){
      alert("A key was pressed!");
      // IE handling
      if (window.event){
        evnt = window.event;
        alert(evnt.keyCode);
      // netscape/mozilla handling 
      else{
        alert(evnt.which);
    //-->
    </script>
    </head>
    <body >
    <form name="myform" method="post">
    Test <input type="text" name="myTest"><BR>
    Test <input type="text" name="myTest2" onKeyPress="check();"><BR>
    <script> document.myform.myTest.onkeypress = check; </script>
    </form>
    </body>
    </html>

  • KeyListener - how to handle series of key pressed

    Hi,
    Is there a way to handle a series of key pressed in the keyPressed(KeyEvent e) method. for instance, I want to popup a dialogbox when the user pressed: F9, 31, F9 ?
    thanks,
    chau

    Is there a way to handle a series of key pressed in
    the keyPressed(KeyEvent e) method. for instance, I
    want to popup a dialogbox when the user pressed: F9,
    31, F9 ?Look at the following.
    import java.awt.event.*;
    import javax.swing.*;
    /* http://forum.java.sun.com/thread.jspa?messageID=2900727 */
    /* http://forums.devshed.com/t218618/s.html */
    class KeyListenerDemo {
        public static void main(String[] args) {
            new KeyListenerDemo().go();
        void go() {
            JTextField field = new JTextField("Press a key, and watch the console.");
            field.setEditable(false);
            field.addKeyListener(new MyKeyListener());
            JFrame frame = new JFrame("KeyListener Demo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(field);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    class MyKeyListener extends KeyAdapter {
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ESCAPE) System.exit(0);
            System.out.println("Typed: " + e.getKeyChar());
    }It shouldn't take too much imagination to figure out how to make the listener listen for that combination....

Maybe you are looking for