use of javax.swing.text.TabSet in project java-swing-tips by aterai.
the class WhitespaceLabelView method install.
@Override
public void install(JEditorPane c) {
FontMetrics fm = c.getFontMetrics(c.getFont());
int tabLength = fm.charWidth('m') * 4;
// TabStop[] tabs = new TabStop[100];
// for (int j = 0; j < tabs.length; j++) {
// tabs[j] = new TabStop((j + 1f) * tabLength);
// }
TabStop[] tabs = IntStream.range(0, 100).mapToObj(i -> (i + 1f) * tabLength).map(TabStop::new).toArray(TabStop[]::new);
TabSet tabSet = new TabSet(tabs);
StyleConstants.setTabSet(ATTRS, tabSet);
super.install(c);
}
use of javax.swing.text.TabSet in project org.alloytools.alloy by AlloyTools.
the class OurSyntaxDocument method do_setFont.
/**
* Changes the font and tabsize for the document.
*/
public final void do_setFont(String fontName, int fontSize, int tabSize) {
if (tabSize < 1)
tabSize = 1;
else if (tabSize > 100)
tabSize = 100;
if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize)
return;
this.font = fontName;
this.fontSize = fontSize;
this.tabSize = tabSize;
for (MutableAttributeSet s : all) {
StyleConstants.setFontFamily(s, fontName);
StyleConstants.setFontSize(s, fontSize);
}
do_reapplyAll();
// this
BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
// is
// used
// to
// derive
// the
// tab
// width
int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
TabStop[] pos = new TabStop[100];
for (int i = 0; i < 100; i++) {
pos[i] = new TabStop(i * gap + gap);
}
StyleConstants.setTabSet(tabset, new TabSet(pos));
setParagraphAttributes(0, getLength(), tabset, false);
}
Aggregations