Search code examples
javajtextarearight-to-leftsetfocus

how to set JtextArea focus in right position?


when i enable or request focus in text area the focus or caret anything u name it, it located at left. but when i start typing, it change to right. please help me to make it on right when request focus(true); this is the properties of textarea:

textManualIn = new JTextArea();
textManualIn.setLocale(new Locale("ar", "AE"));
textManualIn.setMinimumSize(new Dimension(5, 22));
textManualIn.setPreferredSize(new Dimension(5, 22));
textManualIn.setFocusCycleRoot(true);
textManualIn.setFocusTraversalPolicyProvider(true);
textManualIn.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
textManualIn.setRequestFocusEnabled(true);
textManualIn.setFont(new Font("Calibri", Font.PLAIN, 14));
textManualIn.setSelectionColor(new Color(153, 255, 255));
textManualIn.setMargin(new Insets(2, 5, 2, 5));
textManualIn.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
textManualIn.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
textManualIn.setCaretColor(Color.BLACK);
textManualIn.setBackground(new Color(255, 255, 255));
mainmanual.add(status);//add to Jpanel

Solution

  • This is not perfect, but you can try this code:

    textManualIn.setText(" "); // one space
    // And use one of the following
    textManualIn.setCaretPosition(0);
    // -or-
    textManualIn.select(0, 1);