#StackBounty: #java #if-statement #textarea #keypress #keylistener create if statement on each individual line of a textarea object

Bounty: 50

My java code is trying to create a if statement based on if the individual line of the text area object is filled or not. My code works when there is nothining in the text area box however as soon as a character is entered the if text is empty does not work anymore.As you can see in the gif. When a character is entered and the user hits enter even though the line has nothing on it. Sam is still added to the line. That should not happen. Sam should be only added to the line if character is on the line.

enter image description here

public void keyPressed(KeyEvent e) {
   if(e.getKeyCode() == KeyEvent.VK_ENTER){

       if(text11.jt.getText().trim().isEmpty()) {

           System.out.println( "Hi" );

       else {
           text11.jt.setText(text11.jt.getText() + "     sam");



Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.