⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e985. setting the tab size of a jtextarea component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -