/** * 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); @SuppressWarnings("deprecation") 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); }
/** * 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); @SuppressWarnings("deprecation") 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); }
tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE); tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs);
private void setTabStops() { final Document doc = edit_.getDocument(); if (doc instanceof PlainDocument) { doc.putProperty(PlainDocument.tabSizeAttribute, 8); } else if (doc instanceof DefaultStyledDocument) { final TabStop[] tabs = new TabStop[20]; for (int i = 0; i < tabs.length; i++) { tabs[i] = new TabStop((i+1) * 20); } final TabSet tabSet = new TabSet(tabs); final SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet); final int length = doc.getLength(); ((DefaultStyledDocument) doc).setParagraphAttributes(0, length, attributes, false); } else { ; // do nothing - don't know how to do it } }
@Override public void updateUI() { super.updateUI(); setOpaque(false); putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); EventQueue.invokeLater(() -> { // MutableAttributeSet attr = new SimpleAttributeSet(); Style attr = getStyle(StyleContext.DEFAULT_STYLE); TabStop[] ts = {new TabStop(25f, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE)}; StyleConstants.setTabSet(attr, new TabSet(ts)); setParagraphAttributes(attr, false); }); } };
TabSet tabSet = new TabSet(tabs);
private static final SimpleAttributeSet ATTRIBS = new SimpleAttributeSet(); private static final TabStop TAB_STOP = new TabStop(POS, ALIGN, LEADER); private static final TabSet TAB_SET = new TabSet(new TabStop[] { TAB_STOP });
private void RebuildStyles() { send(" "); StyleConstants.setAlignment(m_objMainStyle, StyleConstants.ALIGN_LEFT); StyleConstants.setFontFamily(m_objMainStyle, m_objChatterFont.getFamily()); StyleConstants.setFontSize(m_objMainStyle, m_objChatterFont.getSize()); StyleConstants.setSpaceAbove(m_objMainStyle, 2); StyleConstants.setSpaceBelow(m_objMainStyle, 2); send("- Chatter font changed"); send(" "); FontMetrics l_objFM = m_objChatPanel.getFontMetrics(m_objChatterFont); float l_f = (float)l_objFM.stringWidth(BEFORE_CATEGORY + ASLDiceBot.OTHER_CATEGORY + "XXX"); TabStop[] lar_objTabs = new TabStop[10]; // this sucks for(int l_i = 0; l_i < lar_objTabs.length; l_i++) { lar_objTabs[l_i] = new TabStop(l_f * (l_i + 1), TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); } TabSet l_objTabset = new TabSet(lar_objTabs); StyleConstants.setTabSet(m_objMainStyle, new TabSet(new TabStop[0])); StyleConstants.setTabSet(m_objMainStyle, l_objTabset); m_objChatPanel.setParagraphAttributes(m_objMainStyle, true); }
TabSet tabSet = new TabSet(tabs); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet);
TabSet tabSet = new TabSet(tabs); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet);
@SuppressWarnings("deprecation") public static void createTabs(JTextPane textPane) { int tabSize = AWPrefs.getEditorTabSize(); int charWidth = AWPrefs.getEditorFontSize(); try { charWidth = Toolkit.getDefaultToolkit().getFontMetrics(textPane.getFont()).stringWidth("m"); } catch(Exception e) { // ignore exception } TabStop[] tstops = new TabStop[100]; for(int i = 0; i<100; i++) { tstops[i] = new TabStop(i*tabSize*charWidth); } TabSet tabs = new TabSet(tstops); Style style = textPane.getLogicalStyle(); if(style != null) { StyleConstants.setTabSet(style, tabs); textPane.setLogicalStyle(style); } }
private void setTabSize(int tabSize) { document.setTabSize(tabSize); FontMetrics fm = getFontMetrics(getFont()); int charWidth = fm.charWidth('#'); int tabWidth = charWidth * tabSize; TabStop[] tabs = new TabStop[100]; for (int j = 0; j < tabs.length; j++) { tabs[j] = new TabStop((j + 1) * tabWidth); } SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, new TabSet(tabs)); getDocument().removeUndoableEditListener(undoManager); // Avoid this change to be undone getStyledDocument().setParagraphAttributes(0, getDocument().getLength(), attributes, false); getDocument().addUndoableEditListener(undoManager); }
tabs[2] = new TabStop(300, TabStop.ALIGN_LEFT,TabStop.LEAD_NONE); tabs[3] = new TabStop(400, TabStop.ALIGN_LEFT,TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs);
tabs[i] = new TabStop(width * (tabSize + tabSize * i)); TAB_SET = new TabSet(tabs); StyleConstants.setTabSet(commentAttributes, TAB_SET); StyleConstants.setTabSet(javadocAttributes, TAB_SET);