/** * sets the number of characters per tab. * * @param charactersPerTab the characters per tab */ public void setTabs(int charactersPerTab) { Font f = new Font(m_FontName, Font.PLAIN, m_FontSize); FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f); int charWidth = fm.charWidth('w'); int tabWidth = charWidth * charactersPerTab; TabStop[] tabs = new TabStop[MAX_TABS]; for (int j = 0; j < tabs.length; j++) tabs[j] = new TabStop((j + 1) * tabWidth); TabSet tabSet = new TabSet(tabs); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet); int length = getLength(); setParagraphAttributes(0, length, attributes, false); }
private void setTabSize(int charactersPerTab) { FontMetrics fm = this.getFontMetrics(this.getFont()); int charWidth = fm.charWidth('w'); int tabWidth = charWidth * charactersPerTab; TabStop[] tabs = new TabStop[10]; for (int j = 0; j < tabs.length; j++) { int tab = j + 1; tabs[j] = new TabStop(tab * tabWidth); } TabSet tabSet = new TabSet(tabs); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setFontSize(attributes, 18); StyleConstants.setFontFamily(attributes, "Osaka-Mono"); StyleConstants.setTabSet(attributes, tabSet); int length = getDocument().getLength(); getStyledDocument().setParagraphAttributes(0, length, attributes, true); }