Java Swing How to - Set the Tab Size of a JTextArea








Question

We would like to know how to set the Tab Size of a JTextArea.

Answer

//w ww .  j  av a  2 s .  co  m


import java.awt.Font;

import javax.swing.JTextArea;

public class Main {
  public static void main(String[] argv) {
    JTextArea textarea = new JTextArea();
    // Get the default tab size
    int tabSize = textarea.getTabSize(); // 8

    // Change the tab size
    tabSize = 4;
    textarea.setTabSize(tabSize);

    Font font = textarea.getFont();
    System.out.println(font);
  }
}