Pressing Enter doesnt fire an event to JButton

I have a JButton & when i set some tasks on the actionPerformed(), it works, but only if i click on that button! however,i want this task to be performed even if i hit ENTER!
I used the keyListener & the keyPressed() method, but still no luck! I thought that actionEvent handles the ENTER key presses also!
Where am i going wrong?
sendButton.addKeyListener(new KeyAdapter(){
               public void keyPressed(KeyEvent e){
                    if(e.getKeyCode()==10){
                         System.out.println("ENTER STRUCK");
                         /* some tasks */
          );

Of course it works fine for me too! what i am trying to say is that my appl still doesnt work! ok, i am posting my code here! its a simple chat application! Hope you can solve the problem for me! :-)
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class ChatClient {
     JTextArea incoming;
     JTextField outgoing;
     BufferedReader reader;
     PrintWriter writer;
     Socket sock;
     String user;     
     public static void main(String[] args){
          ChatClient cc = new ChatClient();
          cc.go();
     public void go(){          
          JFrame frame = new JFrame("Client");
          JPanel mainPanel = new JPanel();          
          incoming = new JTextArea(15,50);
          incoming.setLineWrap(true);
          incoming.setWrapStyleWord(true);
          incoming.setEditable(false);
          JScrollPane qScroller = new JScrollPane(incoming);
          outgoing = new JTextField(30);
          JButton sendButton = new JButton("Send");
          mainPanel.add(qScroller);
          mainPanel.add(outgoing);
          mainPanel.add(sendButton);
          frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
          frame.setSize(600,400);          
          frame.setVisible(true);               
          sendButton.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e) {
                    writer.println(outgoing.getText());
                    writer.flush();               
                    outgoing.setText("");
                    outgoing.requestFocus();
          setUpNetworking();
          Thread readerThread = new Thread(new IncomingReader());
          readerThread.start();
     private void setUpNetworking(){
          try {
               sock = new Socket(InetAddress.getLocalHost(),5002);               
               reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
               writer = new PrintWriter(sock.getOutputStream());               
          } catch (UnknownHostException e) { e.printStackTrace(); }
            catch (IOException e) { e.printStackTrace(); }          
     public class IncomingReader implements Runnable {
          public void run() {
               String message;
               try {
                    while((message=reader.readLine())!=null){                    
                         incoming.append(message+"\n");
               } catch (IOException e) { e.printStackTrace(); }
}

Similar Messages

  • Search bar doesnt launch a search when I press Enter key

    When I type something in the search bar, it shows me suggestions. On pressing Enter, it selects the highlighted suggestions. Now that I press Enter again to launch the search query, nothing happens. Search query doesnt go to the network till I mouse-click the lens icon in the search bar.
    This works fine in my windows machine, so I know it is a supported feature.

    No, problems here on Linux with the search bar and the Enter key.<br />
    Do you have the official Firefox version from the Mozilla site or a special Ubuntu branded version?<br />
    Ubuntu usually makes a lot of changes to their branded version and it is possible that they have disabled the Enter key.<br />
    You can try the version from the Mozilla site to see if that works better if you have the Ubuntu version.
    *Firefox 5.0.x: http://www.mozilla.com/en-US/firefox/all.html
    You can create a new profile as a test to check if your current profile is causing the problems.
    See Basic Troubleshooting: Make a new profile:
    *https://support.mozilla.com/kb/Basic+Troubleshooting#w_8-make-a-new-profile
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins" in case there are still problems.
    If that new profile works then you can transfer some files from the old profile to that new profile (be careful not to copy corrupted files)
    See:
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • JButton actionPerformed by pressing enter

    hi all
    i have my little form when my users have to insert userName and password
    i'd like that they can start the login method only by pressing enter, not by pressing my jbutton
    any advice?
    thanx
    sandro

    The solution involves setDefaultButton(..), but its not quite that simple. Check out this thread:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=288909

  • Propagating event when pressing ENTER

    Hi to all.
    I have JDialog and i have added JButton as getRootPane().setDefaultButton(ok); ok is that button.
    I have added action listener to that button. In my app, after this JDialog, i have another JDialog asking for something. If i click with mouse i can see that next dialog, but if i press enter, actionPerformed on my dialog is executing, and is prolongating on that other JDialog. It is acting like i have pressed Enter on that other dialog too. I want to stop this. How can i do this?

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.
    To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    db

  • MODULE POOL WHEN WE PRESS ENTER KEY IN A TBL CONTROL THEN CURSOR GO TO FIRS

    DEAR ALL,
                    IN MODULE POOL WHEN WE PRESS ENTER KEY IN A TBL CONTROL THEN CURSOR GO TO FIRST INPUT/OUTPUT BOX  I WANT THE CURSOR WILL STAY ON THAT TBL CONTROL COLUMN.
      PLZ TELL ME HOW I CAN DO THIS.
    THANKS
    SHASHI
    Moderator message: no upper case please, search for available information before posting.
    Edited by: Thomas Zloch on Mar 11, 2011 11:50 AM

    Hi,
    This is possible only for check boxes and radio buttons.
    for others you atleast need to double click.
    please note double click is possible.
    regards
    Ramchander Rao.Krishnamraju

  • Strange behavior when pressing ENTER in a form page

    Hi there
    Please go to the address:
    http://apex.oracle.com/pls/otn/f?p=20104:4
    If you click the Create button, enter anything in the Name field and press ENTER while in the field, you will be taken back to the main page, the message Action Processed will be displayed, but no data will be inserted. If you click on the Create button though, it works fine.
    Have anyone seen this? Any explanation for it? How to fix it? I could not find any reason for this behavior (the Name field is NOT an always submit page when enter pressed field type).
    (btw the two pages are very simple, based on wizards without any customisation)
    Thanks
    Luis

    i guess, trying the input form, the input text field for Name is an item 'textfield submit on enter'. But what happens is that when enter is pressed no additionally submit information is send, which is the case with buttons. Buttons call the doSubmit('<BUTTONNAME>') javascript function on click, allowing the process to run when thee are set conditionally.
    Carl's answer by setting the process unconditional will also result this action will take place when another buton (without direct redirect) will fire this.).
    So additionally when multple buttons and processes some new javascript kan be used to do the right submit on Enter. Example:
    In Page header, or shared javascript import file create a JS function submitOnEnter
    function submitOnEnter(submit,e){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13){
    doSubmit(submit);
    return false;
    }else{
    return true;
    Then with you're item you define the js-event onKeyPress to call the function submitOnEnter
    onkeypress="javascript:return submitOnEnter('CREATE',event);"

  • Clearing the TextArea texts when I press Enter key

    How to clear the texts that I have typed into the TextArea when I press Enter Key?
    I have now added a TextArea instance called input_txt to the stage and added an component event listener to detect when I press enter key. Then an event fires up which first reads the input to a string variable.
    But next I need to automatically clear the texts in the TextArea.
    How to do that?
    function readInput(event:Event):void
        input = input_txt.text;
        trace(input);
        // removing texts in the text input area-------- how?
    input_txt.addEventListener(ComponentEvent.ENTER, readInput);
    Please help.
    Thank You

    ComponentEvent.ENTER occurs before the line feed is added to the text, and is not cancelable, so you'll probably need to set a flag and do the clearing in an Event.CHANGE handler. Something like this:
    import fl.events.ComponentEvent;
    input_text.addEventListener(ComponentEvent.ENTER, readInput);
    input_text.addEventListener(Event.CHANGE, changeHandler);
    var clearing:Boolean=false;
    function readInput(event:Event):void
        input = input_txt.text;
        trace(input);
        clearing=true;
    function changeHandler(event:Event)
    if(clearing)
      input_text.text="";
      clearing=false;

  • By pressing enter key on button?

    By pressing ENTER key on key board on button(SUBMIT) how i get action perform.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class loginform {
         public static void main(String a[]) {
              loginform1 s = new loginform1();
              s.setSize(800, 600);
              s.setVisible(true);
    class loginform1 extends JFrame implements ActionListener {
         JTextField user;
         JPasswordField pass;
         JButton submit;
         public loginform1() {
              setLayout(null);
              Container c = getContentPane();
              JLabel JLabel1 = new JLabel("User Name:");
              c.add(JLabel1);
              JLabel1.setBounds(220, 205, 90, 20);
              JLabel JLabel2 = new JLabel("Password:");
              c.add(JLabel2);
              JLabel2.setBounds(220, 245, 90, 20);
              user = new JTextField();
              c.add(user);
              user.setBounds(300, 205, 130, 20);
              setVisible(true);
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        user.requestFocus();
              pass = new JPasswordField();
              c.add(pass);
              pass.setBounds(300, 245, 130, 20);
              submit = new JButton("Submit");
              c.add(submit);
              submit.setBounds(320, 290, 80, 20);
              submit.addActionListener(this);
              WindowListener l = new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              addWindowListener(l);
         public void actionPerformed(ActionEvent ae1) {
              if (ae1.getSource() == submit) {
                   String s1 = user.getText();
                   String s2 = pass.getText();
              System.out.println(s1);
              System.out.println(s2);
    }how to get that one.
    thanks in advance
    raja

    add this to loginform1's constructor
    this.getRootPane().setDefaultButton(submit);

  • Pressing enter to add a row?

    I recently upgraded to Numbers 3.5.2.  Prior to the upgrade, if I wanted to add a row to a table, I simply pressed 'Enter' and a row automatically added below whatever cell was currently selected.  It also added the data entered into the new cell to the formula of the cell(s) above it.  Since upgrading, I have to manually add a row and include the data in the formula...  Any ideas if this is simply a setting?  If so, which one?!

    th eeasiest way to do this is to implement an ActionListener 9which then, you must implement the actionPerformed(ActionEvent e) method
    example:
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    class Demo extends JFrame implements ActionListener{
        private JButton btnExit = null;
        private JButton btnBrowse = null;
        public Demo(){
            btnExit = new JButton("Exit");
             // tell what action listener to use, which is this class (since we implements
            //  the ActionListener
            btnExit(AddActionListener(this);               
            getContentPane().add(btnExit, "South");
            btnBrowse = new JButton("Browse");
            btnBrowse.addActionListener(this);
       // This method is the implementation of the ActionListener interface
        public void actionPerformed(ActionEvent e){
            Object o = event.getSource();  // return the object that trigger the action event
            if (o == btnExit){  // the object triggered is the exit button
                this.dispose();  // dispose the JFrame
                System.exit(0); // wuit the application
            else if (o == btnBrowse){
                JFileChooser fc = new JFileChooser();
                // etc...
    }

  • Selection screen field is not populated without pressing "Enter"

    Hello All,
    I am calling a report from module pool using SUBMIT statement. I have defined a selection screen as subscreen on module pool screen. On this selection screen i have a select option S_BUKRS. When I input company code 1000 and just press execute button on module pool, it is taking me to the report output. But S_BUKRS is not filled before the submit statement and hence report is executing as if S_BUKRS is initial.
    I put a breakpoint and saw that the field S_BUKRS is not filled before calling the repot.
    I re-ran the transaction (module pool) and this time after inputting 1000 in S_BUKRS I pressed enter and then pressed execute button. Now the value is transferred to report since S_BUKRS[] is filled.
    Do I need to press enter key after inputting the values on the selection screen everytime; before pressing the execute button?
    What could be the issue and how can I resolve it?
    I am calling the report in PAI of module pool using statement SUBMIT ZREPORT1 WITH s_bukrs IN s_bukrs AND RETURN.
    Thanks,
    Sandeep

    sandeep akula wrote:
    Hello All,
    > I am calling a report from module pool using SUBMIT statement. I have defined a selection screen as subscreen on module pool screen. On this selection screen i have a select option S_BUKRS. When I input company code 1000 and just press execute button on module pool, it is taking me to the report output. But S_BUKRS is not filled before the submit statement and hence report is executing as if S_BUKRS is initial.
    > I put a breakpoint and saw that the field S_BUKRS is not filled before calling the repot.
    > I re-ran the transaction (module pool) and this time after inputting 1000 in S_BUKRS I pressed enter and then pressed execute button. Now the value is transferred to report since S_BUKRS[] is filled.
    > Do I need to press enter key after inputting the values on the selection screen everytime; before pressing the execute button?
    > What could be the issue and how can I resolve it?
    > I am calling the report in PAI of module pool using statement SUBMIT ZREPORT1 WITH s_bukrs IN s_bukrs AND RETURN.
    > Thanks,
    > Sandeep
    I believe, you should be able to caputre the value of S_BUKRS in AT SELECTION-SCREEN event even if the user executes the program with out hitting Enter key. Make sure that you are including the CALL SUBSCREEN <area> statement in the PAI as the first statement.
    -Rajesh.

  • Error in searching field value by pressing enter

    Hi all,
    I am able to get a pop up with the values of the field and select in that pop up to the main screen on pressing enter.
    But i get all the values of the column present in the table and not the one which i want to search. Also the main screen gives error message if the cursor is in the field on main page and works properly  if the cursor is not there in the field.
    Error is as follows:
    <b>BSP exception: Access to URL /sap(bD1lbiZjPTAwMQ==)/bc/bsp/sap/z_startingwith/POST is forbidden</b>
    Does it have anything to do with <form method = "POST">
    as the values from main screen are not passing to the next screen!!
    <b>Find.htm:</b> (Main screen)
    <%@page language="abap" %>
    <%@extension name="htmlb" prefix="htmlb" %>
    <script language="JavaScript" type="text/javascript">
    document.onkeydown = function(){
    if(window.event && window.event.keyCode == 13)
                  popUp=window.open('help.htm','_blank', 'Emp Details','width=100,height=300');
    </script>
    <htmlb:content design="design2003" >
      <htmlb:page title="Add Employee Details " >
        <htmlb:form action="POST" id = "form1">
          Empid:
          <htmlb:inputField id          = "partner"
                            showHelp    = "true"
                           submitOnEnter = "true"
                            value       = "<%= partner %>" />
        </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    <b>Help.htm</b>
    <%@page language="abap" %>
    <%@extension name="htmlb" prefix="htmlb" %>
    <htmlb:content design="design2003" >
      <htmlb:page title="Test" >
        <htmlb:form id="my_window" >
          <%
      data TV_ITERATOR Type Ref To zcl_itr." - Iterator Function
      data iterator type ref to IF_HTMLB_TABLEVIEW_ITERATOR.
      create object tv_iterator exporting appl_cons = appl.
      iterator = tv_iterator.
          %>
          <htmlb:tableView id               = "pop"
                           width            = "200"
                           headerVisible    = "true"
                           design           = "alternating"
                           visibleRowCount  = "10"
                           fillUpEmptyRows  = "true"
                           selectionMode    = "SINGLESELECT"
                           selectedRowIndex = "<%= row_index %>"
                           onRowSelection   = "MyEventRowSelection"
                           showNoMatchText  = "true"
                           filter           = "server"
                           sort             = "server"
                           onHeaderClick    = "MyEventHeaderClick"
                           table            = "<%= details %>"
                           iterator         = "<%= iterator %>" >
          </htmlb:tableView>
          <%
      if partner is not initial.
          %>
          <htmlb:inputField id      = "checked"
                            visible = "True"
                            value   = "<%= partner %>" />
                <script for="checked" language="javascript" event="onLoad()">
                       opener.document.form1.partner.value = <%= partner %>;
                       window.self.close();
          </script>
          <%
      endif.
          %>
        </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    <b>Oncreate:</b>
    select partner from zcrmm_buag into corresponding fields of table details.
    <b>OnInputProcessing:</b>
    DATA: IND TYPE I.
      DATA: TV TYPE REF TO CL_HTMLB_TABLEVIEW.
      DATA: EVENT1 TYPE REF TO CL_HTMLB_EVENT.
      EVENT1 = CL_HTMLB_MANAGER=>GET_EVENT( RUNTIME->SERVER->REQUEST ).
      TV ?= CL_HTMLB_MANAGER=>GET_DATA(
      REQUEST = RUNTIME->SERVER->REQUEST
      NAME = 'tableView'
      ID = 'pop' ).
      IF TV IS NOT INITIAL.
        DATA: TV_DATA TYPE REF TO CL_HTMLB_EVENT_TABLEVIEW.
        TV_DATA = TV->DATA.
        IF TV_DATA->SELECTEDROWINDEX IS NOT INITIAL.
          FIELD-SYMBOLS: <row> LIKE LINE OF details.
        READ TABLE details INDEX tv_data->selectedrowindex ASSIGNING <row>.
    if <row> is assigned.
    partner = <row>-partner.
    endif.
        ENDIF.
      ENDIF.
    Any help is welcome.
    Regards,
    Rohit Khetarpal

    <i>actually when the pop up comes,the page on the back(i.e. Find.htm) shows error message as mentioned below..
    BSP exception: Access to URL /sap(bD1lbiZjPTAwMQ==)/bc/bsp/sap/z_startingwith/POST is forbidden</i>
    -->Remove "method="post" in FORM tag. I tested.
    <b>To pass the value from Find.htm to Help.htm</b> - see the below code
    <script language="JavaScript" type="text/javascript">
    document.onkeydown = function(){
    if(window.event && window.event.keyCode == 13)
    var val;
    val = document.getElementById("partner").value;
    * Here the VAL will have the value of query value(what user entered as Filter value) from Find.htm
    popUp=window.open('help.htm?partner'+val,'_blank', 'Emp Details','width=100,height=300');
    </script>
    <b>And also make the "Patner" in help.htm as "AUTO parameter.</b>
    Hope this will solve your peoblme.
    Raja T
    Message was edited by:
            Raja Thangamani

  • Trigger PAI after pressing enter key

    Hi all,
    How to trigger the PAI event after pressing the enter key on the keyboard. i have a input field and a button on the screen. after entering the value into the field and pressing buttot will take to next screen. But if I press enter key the value is getting cleared. How to trigger the PAI event after pressing the enter key?
    Thanks in advance,
    Dev.

    Hi,
    The keyboard event 'Enter' does not have a default sy-ucomm or a Function code associated with it.
    So, whenever you press Enter, it triggers the PAI (sy-ucomm would be blank) and somewhere in your code the value is being refreshed. You can debug thoroughly to find where the problem is.
    You can assign a Function code for Enter. Go to the GUI Status of the Screen -> Function Keys -> You will find a icon Enter (the one with the tick mark in a green circular background) -> Assign Function code like 'ENTER'.
    Now in your PAI, restrict your code saying
    if sy-ucomm = 'ENTER'.
    "Logic
    endif.

  • How to submit a form by pressing enter key

    Hi,
    I'm having a problem..............i have a form having text field and a button created using struts html tags..........when user enters the value and presses the button then the value is being taken...........
    but if the user enters the data and just presses enter key the form refreshaes but value is not submitted.............
    the button is created using <html:submit >tag.............can any one pls help me out with this???????????

    <script language="JavaScript">
    <!--
    var isNav, isIE
    if (parseInt(navigator.appVersion) >= 4) {
    if (navigator.appName == "Netscape")
    isNav = true
    else
    isIE = true
    function showKeyValue(evt) {
    var keyValue
    if (isNav)
    keyValue = evt.which
    else
    keyValue = window.event.keyCode
    /*status = keyValue*/
    if (keyValue == 13) {
    javascript:validateForm();
    return false
    </script>
    in the field call this method
    onKeyPress="showKeyValue(event)"

  • BUG:Pressing Enter in Form gives no data found

    Hello,
    The accept procedure which is the generic
    handler for the forms needs to know the form
    id, and other parameter that are set by the
    doevent javascript function, invoked when a button is clicked. Instead of clicking the button(s), if user presses enter, the accept procedure will not know which form to instantiate as a result it throws a no data found error.
    Possible solution:
    1. Adding javascript to cancel keypress by using the keypress event. Does not work.
    2. Form level javascript to detect keypresses. For this you need to allow us to access the <HEAD></HEAD> in the form. We need to add javascvript which detects the type of browser and modifies the keypress detection accordingly.
    there are a couple of more ways

    Hi SYR,
    Pick Slip report gives you out put as NO DATA FOUND, is basically, bcos there has not been any picking of the item, reason may be,
    1. Qty avaialble wont be reservable and transactable
    Check in Inventory> On handqty > click availibility tab
    And see whether the item is available to transact & reserve.
    If you have enought qty thn you shld be able to pick release tht item.
    2. Check which sub inventory are you using while pick release, is it the same as where the item is kept.
    Try this out.
    This may help.
    Thanks
    Manoj

  • Upon Pressing Enter Key in an InputField

    Hi,
    I have an InputField where i have to enter AirlineId and followed by search button
    But my requirement here is <b>
    We have to press Enter key in INputField.Then all the AirLineIds which are there in the database has to be popuped and in that the one which selects has to be placed in the InputField</b>
    Regards
    Padma

    Hi Padma,
                      Create a onEnter event for the input field & inside that create a modal window. For that window u have to create a view also.
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/wd%20java/wd%20tutorials/dialog%20boxes%20in%20web%20dynpro%20applications.pdf">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/wd%20java/wd%20tutorials/dialog%20boxes%20in%20web%20dynpro%20applications.pdf</a>
    In this tutorial check the code for AddressBook(not for external window) .U can use this code
    IWDWindowInfo myWinInfo = wdComponentAPI.getComponentInfo().findInWindows("<window name>");
    myPopupWindow = wdComponentAPI.getWindowManager().createWindow(myWinInfo,true);
    myPopupWindow.setWindowPosition(300,150);
    myPopupWindow.open();
    regards
    Sumit

Maybe you are looking for

  • I lost my photos on my photo stream , how i can get them back? my laptop is a pc, no mac

    this is what happend my iphone 4 got stolen about a month ago, soo i buy a new iphone 4s i used my 4s only with the feedback given by icloud i never connect the new iphone to my latop until today today when i connected the 4s, all the information on

  • MS project 2010 import to P6

    I have this question; When I imported MSP2010 project files (After saving to xml first), the schedule does not come out the way it looked in MSP. Summary tasks do not show up and the sequence is out of whack. Am I doing something wrong? When I import

  • RENL & ENS Connection Pooling - How to ?

    1.How do i acknowledge a notification from a subscriber ? 2.How do i enable ENS Connection Pooling [http://docs.sun.com/app/docs/doc/819-2655/6n4u96geu?a=view] ? It would be better if somebody could give me code snippet also for the same.

  • High-quality YouTube videos keep crashing.  What should I do???

    Whenever I open a higher quality youtube video on ipad, it plays for a couple of seconds and then it crashes and sends me back to the Home screen.  I tried to updating it to the latest version of iOS about a week and a half ago, and that helped at fi

  • Can't install 1.84.55 driver upda

    This is really a weird problem: I have an Audigy 2, recently I noticed that there was a new driver update for the audigy 2/ZS, which is the 2 may 05/.84.55 driver. When I run the setup and click "Ok" to continue, I get an error saying: "Setup could n