• <small id='o1Aay'></small><noframes id='o1Aay'>

      <legend id='o1Aay'><style id='o1Aay'><dir id='o1Aay'><q id='o1Aay'></q></dir></style></legend>
      <tfoot id='o1Aay'></tfoot>
    1. <i id='o1Aay'><tr id='o1Aay'><dt id='o1Aay'><q id='o1Aay'><span id='o1Aay'><b id='o1Aay'><form id='o1Aay'><ins id='o1Aay'></ins><ul id='o1Aay'></ul><sub id='o1Aay'></sub></form><legend id='o1Aay'></legend><bdo id='o1Aay'><pre id='o1Aay'><center id='o1Aay'></center></pre></bdo></b><th id='o1Aay'></th></span></q></dt></tr></i><div id='o1Aay'><tfoot id='o1Aay'></tfoot><dl id='o1Aay'><fieldset id='o1Aay'></fieldset></dl></div>

          <bdo id='o1Aay'></bdo><ul id='o1Aay'></ul>

      1. 在 Swing 中停止事件的默认行为

        时间:2023-09-30
      2. <i id='wZn3o'><tr id='wZn3o'><dt id='wZn3o'><q id='wZn3o'><span id='wZn3o'><b id='wZn3o'><form id='wZn3o'><ins id='wZn3o'></ins><ul id='wZn3o'></ul><sub id='wZn3o'></sub></form><legend id='wZn3o'></legend><bdo id='wZn3o'><pre id='wZn3o'><center id='wZn3o'></center></pre></bdo></b><th id='wZn3o'></th></span></q></dt></tr></i><div id='wZn3o'><tfoot id='wZn3o'></tfoot><dl id='wZn3o'><fieldset id='wZn3o'></fieldset></dl></div>

          <small id='wZn3o'></small><noframes id='wZn3o'>

        1. <legend id='wZn3o'><style id='wZn3o'><dir id='wZn3o'><q id='wZn3o'></q></dir></style></legend>

              1. <tfoot id='wZn3o'></tfoot>
                  <bdo id='wZn3o'></bdo><ul id='wZn3o'></ul>
                    <tbody id='wZn3o'></tbody>
                  本文介绍了在 Swing 中停止事件的默认行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在通过单击发送按钮或在一段代码的消息文本字段中按 Enter 调用的方法中有以下代码.

                  I have the following bit of code in a method called by clicking the send button, or pressing enter in the message text field in a piece of code.

                  // In class ChatWindow
                  private void messageTextAreaKeyPressed(java.awt.event.KeyEvent evt) { // Event handler created by Netbeans GUI designer to call this method.           
                      if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                          sendMessage();
                      }
                  }   
                  public void sendMessage() {
                      String currentMessage = messageTextArea.getText();
                      addMessage("You", currentMessage);
                      app.sendMessage(currentMessage, 1);
                      messageTextArea.setText("");
                  }
                  

                  最后一段代码使文本区域空白.但是,在按回车键发送消息后,文本框不是空的,而是包含换行符.

                  The last bit of code blanks the text area. However, after a message is sent by pressing the enter button, rather than being empty, the text box contains a newline.

                  我的猜测是,在我的事件处理程序运行后,将添加换行符.如何停止添加换行符?

                  My guess is that after my event handler runs, THEN the newline character is being added. How to I stop the newline being added?

                  推荐答案

                  尝试在调用 sendMessage()

                  private void messageTextAreaKeyPressed(java.awt.event.KeyEvent evt) { 
                   if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                      sendMessage();
                      evt.consume();
                   }
                  }  
                  

                  这篇关于在 Swing 中停止事件的默认行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:JavaFX 2 事件分派到底层节点 下一篇:java中的事件处理和java中actionPerformed方法的执行

                  相关文章

                  最新文章

                  <legend id='MSzg5'><style id='MSzg5'><dir id='MSzg5'><q id='MSzg5'></q></dir></style></legend>
                      <bdo id='MSzg5'></bdo><ul id='MSzg5'></ul>
                  1. <small id='MSzg5'></small><noframes id='MSzg5'>

                    <tfoot id='MSzg5'></tfoot>
                    <i id='MSzg5'><tr id='MSzg5'><dt id='MSzg5'><q id='MSzg5'><span id='MSzg5'><b id='MSzg5'><form id='MSzg5'><ins id='MSzg5'></ins><ul id='MSzg5'></ul><sub id='MSzg5'></sub></form><legend id='MSzg5'></legend><bdo id='MSzg5'><pre id='MSzg5'><center id='MSzg5'></center></pre></bdo></b><th id='MSzg5'></th></span></q></dt></tr></i><div id='MSzg5'><tfoot id='MSzg5'></tfoot><dl id='MSzg5'><fieldset id='MSzg5'></fieldset></dl></div>