首页javajtextareaJava Swing - 如何设置JTextArea的Tab Size

Java Swing - 如何设置JTextArea的Tab Size

我们想知道如何设置JTextArea的Tab Size。


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);
  }
}