0

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);
Alex
  • 491
  • 2
  • 10
  • 25

2 Answers2

0

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.

Amit Bhati
  • 5,569
  • 1
  • 24
  • 45
0

One easy way to understand it is to keep adding spaces at the start until you have filled the whole line:

 String s = message;
 while (s.length() < 25) {
 s = " " + s;

}