在StyledDocument中更改特定的String属性 [英] Change specific String attributes in StyledDocument

查看:107
本文介绍了在StyledDocument中更改特定的String属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个文本编辑器.我正在将JTextPane与StyledDocument一起使用.我正在尝试实现的是一种更改所选文本的属性的方法.

I am trying to create a text editor. I am using a JTextPane with a StyledDocument. What I am trying to implement is a way to change the attributes of selected text.

这可以通过以下方式进行:用户输入所需的文本.之后,他可以通过选择并按下按钮来更改任何String的属性(字体系列,字体大小,是否为粗体/斜体),然后通过复选框和下拉列表选择所需的更改.

This works in the following way : the user inputs the desired text. Afterwards, he can change any String's attributes (Font family, font size, whether it is bold/italic or not) by selecting it and pressing a button, where by means of checkboxes and dropdown lists would select the desired changes.

是否可以在不重建文档的情况下更改所选String的属性?我一直在搜索,但找不到合适的解决方案.

Is it possible for me to change that selected String's attributes without the need to rebuild the document? I have been searching but was unable to find a proper solution.

推荐答案

您可以使用StyledEditorKit提供的操作,见 ,并在 如何使用编辑器窗格和文本窗格 .

You can use the actions provided by the StyledEditorKit, seen here and discussed in How to Use Editor Panes and Text Panes.

这篇关于在StyledDocument中更改特定的String属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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