Search code examples
javaalignmenttextarea

Java Text align not working


I want that the text that I enter in the textarea is at the right. So i enter this code (chatArea.append(loginName + ": " + message + "\n");) and when i execute the program, the text is at the left. I now thats a stupid question but i'm new at java.

Here my code:

dbHandler.saveNewMessage(message, loginName);
messageInsert.setText("");
chatArea.append(loginName + ": " + message + "\n");
chatArea.setAlignment(chatArea.RIGHT);

Solution

  • Change the code like below:

    dbHandler.saveNewMessage(message, loginName);
    messageInsert.setText("");
    chatArea.append(loginName + ": " + message + "\n");
    chatArea.setRTL(true);
    chatArea.setAlignment(TextArea.LEFT);
    

    In above code, we are activating RTL for TextArea, hence the directions of the text rendering is reversed therefore Left is considered as Right i.e. just like mirror. This effect can be considered like mirroring effect.