JTextPane indentation

随声附和 提交于 2020-01-03 18:59:20

问题


Is there a way to indent a block of text in a JTextPane?


import javax.swing.*;
import java.awt.*;
import javax.swing.text.StyledDocument;

public class SimpleTextPane {

    public static void main(String... args){
        JFrame frame = new JFrame();
        JTextPane textPane = new JTextPane();
        textPane.setPreferredSize(new Dimension(400, 400));
        StyledDocument doc = textPane.getStyledDocument();
        try {
            doc.insertString(doc.getLength(), "Now he has departed from this strange world a little ahead of me. That means nothing. People like us, who believe in physics, know that the distinction between past, present, and future is only a stubbornly persistent illusion", doc.getStyle(""));
            doc.insertString(doc.getLength(), "\n\n" + "I WOULD LIKE TO BE INDENTED Yes, we have to divide up our time like that, between our politics and our equations. But to me our equations are far more important, for politics are only a matter of present concern. A mathematical equation stands forever.", doc.getStyle(""));
        } catch (Exception e) {
        }
        frame.getContentPane().add(new JScrollPane(textPane));
        frame.setLocationRelativeTo(null);
        frame.pack();
        frame.setVisible(true);
    }
}

回答1:


EDIT:

Use setLeftIndent()

Check this example and this one



来源:https://stackoverflow.com/questions/7052061/jtextpane-indentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!