e985. setting the tab size of a jtextarea component.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 21 行
TXT
21 行
Home > List of Packages > javax.swing.text [49 examples] > JTextArea [7 examples]
e985. Setting the Tab Size of a JTextArea Component
When a tab character (\t) is inserted into a text area, it is represented by a space that is wide enough to reach the next tab stop. The space expands or contracts, if the text preceding it is modified. A tab space cannot be zero-width or wider than a tab stop.
By default, each tab stop is the same width and appears at regular intervals. The tab stop width is controlled by the \meta{tab size}. The tab size specifies a number of characters. The tab width is this value multiplied by the maximal character width in the current font. For example, if the widest character in the current font is 20 pixels and the tab size is 8, the tab width is 160 pixels; tab stops will appear every 160 pixels in the text area.
All tab stops in a JTextArea are left-aligned. For other types of tab stops, a JTextPane must be used; see e993 Customizing Tab Stops in a JTextPane Component.
// Create a text area
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();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?