To get the tab size from a JTextArea, you can use the getTabSize() method −
textArea.getTabSize();
We will assign it to int variable and display the size in the Console −
int size = textArea.getTabSize(); System.out.println("Tab Size = "+size);
The following is an example to set the tab size of a JTextArea −
package my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { JFrame frame = new JFrame(); JTextArea textArea = new JTextArea("This is demo text."); int size = textArea.getTabSize(); System.out.println("Tab Size = "+size); frame.add(textArea); frame.setSize(550,300); frame.setLayout(new GridLayout(2, 2)); frame.setVisible(true); } public static void main(String args[]) { new SwingDemo (); } }
The tab size would be visible in Console −