<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=Java%3AStyledText%E6%98%BE%E7%A4%BA%E8%A1%8C%E5%8F%B7</id>
	<title>Java:StyledText显示行号 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=Java%3AStyledText%E6%98%BE%E7%A4%BA%E8%A1%8C%E5%8F%B7"/>
	<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=Java:StyledText%E6%98%BE%E7%A4%BA%E8%A1%8C%E5%8F%B7&amp;action=history"/>
	<updated>2026-06-03T00:52:40Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=Java:StyledText%E6%98%BE%E7%A4%BA%E8%A1%8C%E5%8F%B7&amp;diff=1187&amp;oldid=prev</id>
		<title>imported&gt;Soleverlee：​以“给Swt的StyledText组件增加行号显示，[http://stackoverflow.com/questions/11057442/java-swt-show-line-numbers-for-styledtext 参考这里] &lt;source lang=&quot;java...”为内容创建页面</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=Java:StyledText%E6%98%BE%E7%A4%BA%E8%A1%8C%E5%8F%B7&amp;diff=1187&amp;oldid=prev"/>
		<updated>2015-04-23T02:51:57Z</updated>

		<summary type="html">&lt;p&gt;以“给Swt的StyledText组件增加行号显示，[http://stackoverflow.com/questions/11057442/java-swt-show-line-numbers-for-styledtext 参考这里] &amp;lt;source lang=&amp;quot;java...”为内容创建页面&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;给Swt的StyledText组件增加行号显示，[http://stackoverflow.com/questions/11057442/java-swt-show-line-numbers-for-styledtext 参考这里]&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
text.addLineStyleListener(new LineStyleListener() {&lt;br /&gt;
            public void lineGetStyle(LineStyleEvent e) {&lt;br /&gt;
                // Set the line number&lt;br /&gt;
                e.bulletIndex = text.getLineAtOffset(e.lineOffset);&lt;br /&gt;
&lt;br /&gt;
                // Set the style, 12 pixles wide for each digit&lt;br /&gt;
                StyleRange style = new StyleRange();&lt;br /&gt;
                style.metrics = new GlyphMetrics(0, 0, Integer.toString(text.getLineCount() + 1).length() * 12);&lt;br /&gt;
&lt;br /&gt;
                // Create and set the bullet&lt;br /&gt;
                e.bullet = new Bullet(ST.BULLET_NUMBER, style);&lt;br /&gt;
            }&lt;br /&gt;
        });&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 text.addModifyListener(new ModifyListener() {&lt;br /&gt;
            public void modifyText(ModifyEvent event) {&lt;br /&gt;
                int maxLine = text.getLineCount();&lt;br /&gt;
                int lineCountWidth = Math.max(String.valueOf(maxLine).length(), 3);&lt;br /&gt;
&lt;br /&gt;
                StyleRange style = new StyleRange();&lt;br /&gt;
                style.background = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);&lt;br /&gt;
                style.metrics = new GlyphMetrics(0, 0, lineCountWidth * 8 + 5);&lt;br /&gt;
                Bullet bullet = new Bullet(ST.BULLET_NUMBER, style);&lt;br /&gt;
                text.setLineBullet(0, text.getLineCount(), null);&lt;br /&gt;
                text.setLineBullet(0, text.getLineCount(), bullet);&lt;br /&gt;
            }&lt;br /&gt;
        });&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Programe]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Soleverlee</name></author>
	</entry>
</feed>