问题标签 [styleddocument]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
97134 浏览

java - JTextPane 附加一个新字符串

在每篇文章中都回答了“如何将字符串附加到 JEditorPane?”这个问题。是这样的

我试过这个:

结果我得到了“终止时间:1000”而没有“进程分布:”

为什么会这样???

0 投票
2 回答
2392 浏览

java - 与 JTextPane 关联的 StyledDocument 的字体

与 JTextPane 关联的 StyledDocument 使用什么字体?默认情况下,它是否使用与 JTextPane 相同的字体?特别是,我想知道字体大小。

0 投票
1 回答
12368 浏览

java - How is word-wrapping implemented in JTextPane, and how do I make it wrap a string without spaces?

How exactly is word-wrapping implemented in JTextPane?

I'm trying to understand exactly how it works so that I can modify the behavior. Right now, if I have a standard JTextPane inside a JScrollPane, it will break text at spaces, but not inside long words - if there is a string of text without spaces that is wider than the window, it won't wrap/break and a horizontal scrollbar will appear. As the text width increases, the width of the ParagraphView (via getWidth()) increases to hold the text.

This article by Lapitsky says that LabelView.getBreakWeight() returns View.ExcellentBreakWeight for labels with spaces and View.GoodBreakWeight for labels without spaces (and the code in GlyphView.java seems to confirm this), so why doesn't it break? Is it somehow returning BadBreakWeight instead of GoodBreakWeight? Or is there some layout problem? Or is there a bug?

Here's some code (for your viewing pleasure):

Note that it still doesn't wrap if I take out the scroll pane and just use the text pane (it just gets clipped as it goes outside the window).


The javadocs for Swing don't seem to go into enough detail on how some objects (like JTextPane, View's, and related objects) work together. Is there any further documentation of the design of such classes, perhaps detailing the purpose of each class and how they all work together? Is it just not publicly available? (Or am I the only one having trouble with things like this? Or is the insufficient documentation limited to things which aren't expected to be dealt with by a typical developer?)

0 投票
2 回答
241 浏览

java - StyleConstants.setBold 中布尔参数的含义是什么?

我想将特定范围内的字符设置为粗体。我怎么能那样做?

上面的代码不能正常工作。但,

此代码工作正常。

StyleConstants.setStrikeThrough(getMainStyle(), {SET/RESET}); 我对 SET/RESET 的假设是否正确,或者为什么使用布尔值?

0 投票
1 回答
2420 浏览

java - 如何使用带有 HTML 的 StyledDocument 进行输出?

我有一个JTextPane,我想使用StyledDocument. 这是我的StyledDocument对象:

现在的问题是,如果我用 html 代码编辑文本,它不会以我想要的方式显示。我希望文本显示为粗体而不是字面<b>Some Text</b>

有没有办法做到这一点?

0 投票
1 回答
1390 浏览

java - 使用 StyledDocument 设置 jTextPane 的样式和文本

我正在创建一个基本的 Swing 应用程序。我有jTextPane和一个按钮。如果用户在jTextPane中选择文本并按下按钮,它会将所选文本加粗。这是通过修改StyleDocument来完成的。

我希望能够暂时保存样式文本,关闭以前的jTextPane,打开一个新的jTextPane,然后根据以前保存的样式文本填充它。jTextPane在构造函数中采用StyleDocument,但是当我尝试使用旧的 StyleDocument 构造新的 jTextPane 时它​​似乎不起作用。我认为这是因为我只是传入了最终被删除的先前 jTextPane StyleDocument 的引用。

有什么方法可以复制或克隆 StyleDocument?我知道它是一个界面,但它使用的是 DefaultStyledDocument 吗?有没有更好的方法来做到这一点?

0 投票
1 回答
567 浏览

java - 用于更改 JTextPane 中文本颜色的 Highlighter 与 Java Swing 的 StyledDocument

我一直在使用setCharacterAttributesofStyledDocument来更改JTextPane.

但后来我注意到这里有一些答案,他们使用Highlighter(通常DefaultHighlighter)来做同样的事情。

这两种方法的本质区别是什么?使用荧光笔比操作 StyledDocument 更好的目的有哪些?

0 投票
1 回答
653 浏览

java - 带有样式块的 JTextField

我需要某种 JTextField,用样式块替换回车符,用另一种字体、样式或颜色显示文本 <New Line>。

例如,文本..

..将在一行 JTextField 中以这种方式显示给用户:

亲爱的史密斯先生,<新线> blablabla... <新线>问候...

这些 <New Line> 应该是可以选择的块,就像它是单个字符一样,并且可以通过单个退格键删除。按回车键将在插入符号位置添加 <New Line>。

我认为可以通过覆盖来实现PlainDocument,但我陷入了难以理解的 Document 和 EditorKit API 中。我需要一些关于这个的指针......

我对使用 a 没有任何异议JTextPaneJEditorPane只要它的行为类似于 a JTextField(一行,没有滚动条)。

有什么建议么?

0 投票
1 回答
10141 浏览

java - java - 如何在java swing JTextPane中附加一个字符串?

我正在创建一个聊天应用程序。在这个聊天应用程序中,我必须使用 Java SwingJTextPane为一些特定的字符串赋予样式,例如用户的显示名称和消息的时间。这就是我选择JTextPaneover的原因JTextArea。在 JTextPane 中,我不能追加字符串,所以我创建了一个字符串缓冲区来追加字符串,然后我做jTextPane.setText(stringBuffer.toString()).

这是我的问题:当我将字符串附加到JTextPanevia aStringBuffer时,会有延迟。如何在 a 中逐行附加字符串JTextPane

0 投票
3 回答
154 浏览

java - 用于加载文档和标记文本部分的 Java 库

我是 Swing 开发的新手,我正在创建一个 Java 应用程序,用户可以在其中加载文本文档并标记部分文本。

然后将突出显示文本的标记部分,用户可以单击标记的文本来编辑/删除标签。有没有我可以用来实现这一目标的库/类。

我已经看过了JTextArea。但据我所知,它只能显示纯文本(如果我错了,请纠正我

为了更清楚我在寻找什么:

当您在 Stack Overflow (SO) 上标记问题时,标签会用一个小框突出显示,并在标签周围突出显示。我在 Java 中寻找类似的东西。

所以,如果我添加的组件是 X,那么 X 应该能够保存纯文本和标记文本。标记的文本应该看起来像 SO 标记。

编辑

一个澄清的例子。

原文:

这是一些示例文本。

标记后,比如说样本,它应该是这样的:

带标记文本

在此处输入图像描述

那 x 基本上是一个按钮,用于删除与sample关联的所有标签。