JTextPane缩进 [英] JTextPane indentation

查看:92
本文介绍了JTextPane缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在JTextPane中缩进一段文本?

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);
    }
}

推荐答案

使用检查此示例这一个

这篇关于JTextPane缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆