Java JTextpane 选项卡大小

Java JTextpane Tab Size(Java JTextpane 选项卡大小)
本文介绍了Java JTextpane 选项卡大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在编写一个 Java 程序,我在程序的某些部分使用了 JTextpane.在这个 JTextpane 中,我使用制表符 ( ) 来制作列,例如:

I am writing a Java program, and I use in some part of the program a JTextpane. In this JTextpane I use tabs ( ) to make columns, something like:

txtpnMTrace = new JTextPane();
txtpnMTrace.setFont(new Font("Dialog", Font.PLAIN, 11));
doc = txtpnMTrace.getStyledDocument();
...
 doc.insertString(doc.getLength(),value1+"	"+value2+"	"+value3+"
", null);

...

我可以在制表符 ( ) 距离处看到列中的值.制表符距离始终相同,我想更改此距离以改善外观.

I can see the values in columns at tab ( ) distance. The tab distance is always the same, and I want to change this distance to improve the look.

您知道如何更改 JTextPane 中的选项卡 ( ) 大小吗?

Do you know How Can I change the tab ( ) size in JTextPane?

提前致谢.

推荐答案

import javax.swing.*;
import javax.swing.text.*;

public class TabExample {

    public static void main(String[] args) {

        JTextPane pane = new JTextPane();
        TabStop[] tabs = new TabStop[4];
        tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
        tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
        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);

        StyleContext sc = StyleContext.getDefaultStyleContext();
        AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
        StyleConstants.TabSet, tabset);
        pane.setParagraphAttributes(aset, false);
        pane.setText("	right	left	center	decimal
" + "	1	1	1	1.0
"
        + "	200.002	200.002	200.002	200.002
"
        + "	.33	.33	.33	.33
");

        JFrame frame = new JFrame("TabExample");
        frame.setContentPane(new JScrollPane(pane));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(360, 120);
        frame.setVisible(true);
    }
}

这篇关于Java JTextpane 选项卡大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)