Note that there are some explanatory texts on larger screens.

plurals
  1. POJTextArea new line on shift + enter
    primarykey
    data
    text
    <p>I've added a keylistener to my JTextArea field, but it doesn't behave as I expected.</p> <pre><code>inputTextArea.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent k) { //If the return button is hit, only set to a new line if shift is also down. if(k.getKeyChar() == KeyEvent.VK_ENTER) { if(k.isShiftDown()) { inputTextArea.append(" \n"); } else { //Send The Message... boolean cleanTextField = false; try { sendMessage(inputTextArea.getText()); cleanTextField = true; msgScrollPane.setAutoscrolls(true); JScrollBar vbar = msgScrollPane.getVerticalScrollBar(); if ((vbar.getValue() + vbar.getVisibleAmount()) == vbar.getMaximum()) { msgPane.setCaretPosition(msgDoc.getLength()); } } catch (Exception ex) { ex.printStackTrace(); cleanTextField = false; } finally { if(cleanTextField) { inputTextArea.setText(""); } } } } } }); </code></pre> <p>I want this: - If the return button is hit and shift is down: add a new line. - If the return button is hit and the shift button isn't down: no new line, but submit.</p> <p>Now it behaves like this: - If I hit the return button and shift is down: no line added. Nothing happens. - If I hit the return button and shift isn't down: submitted, but if I start typing again it begins on new line.</p> <p>Does someone know how to do what I want?</p> <p>EDIT:</p> <p>I tried some other code to detect if the shift button is down:</p> <pre><code> if((k.getModifiersEx() == KeyEvent.SHIFT_DOWN_MASK) || (k.getModifiers() == KeyEvent.SHIFT_DOWN_MASK)) { </code></pre> <p>This doesn't work as well</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload