本文介紹了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 選項卡大小的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!