问题标签 [jtextpane]

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 投票
1 回答
535 浏览

java - 如何阻止我的 JTextPane 吞下键盘快捷键(加速器)?

我的应用程序的主 JFrame 包含一个 JTextPane。虽然它有焦点,但它使用所有键盘快捷键(“加速器”),而不是将它们传递给 JFrame 的 JMenu。这意味着虽然它有焦点,例如“新文档”的 ctrl-n 不起作用。

显然,它正确处理 ctrl-A/C/V/X 以选择全部/复制/粘贴/剪切很有用,但我如何说服它不要吞下其他快捷方式?

0 投票
5 回答
7232 浏览

java - 使用 HTML 的 JTextPane 中的 1 像素表格边框

我正在使用 JTextPane 来显示一些包含带边框的表格的 HTML。我希望它有一个简单的 1 像素边框。

我尝试使用style="border: 1px solid; border-collapse:collapse". 这适用于 Web 浏览器,但不适用于 JTextPane。

有没有办法在 JTextPane 中使用 HTML 来创建一个简单的 1 像素表格边框?

0 投票
3 回答
3659 浏览

java - 逐行读取 JTextPane

有没有办法JTextPane逐行读取内容?很像 BufferedReader?

0 投票
1 回答
1499 浏览

swing - JTextPane editor large file & performance

I'm using a JTextPane to edit XML files. A jflex parser split xml file in tokens and using a custom document (extends DefaultStyledDocument) i color syntax:

doc.setCharacterAttributes(token.getCharBegin() + change, token.getCharEnd() - token.getCharBegin(), Token_Styles_Define.getStyle(token.getDescription()), true);

My problem is to load and edit large xml file, for exemple a 400kb xml file takes 30 seconds and for 700kb 1Mb i get java heap space. I google it and i found :

" Define a limit that JTextPane/JEditorPane can handle well (like 500KB or 1MB). You'll only need to load a chunk of the file into the control with this size. Start by loading the 1st partition of the file. Then you need to interact with the scroll container and see if it has reached the end/beginning of the current chunk of the file. If so, show a nice waiting cursor and load the previous/next chunk to memory and into the text control. The loading chunk is calculated from your current cursor position in the file (offset). loading chunk = offset - limit/2 to offset + limit/2 The text on the JTextPane/JEditorPane must not change when loading chunks or else the user feels like is in another position of the file. This is not a trivial solution but if you don't find any other 3rd party control to do this I would go this way. " (bruno conde)

Is this a good solution and can anybody give me an exemple (link tutorial project) ? or are any other solution? How can we improve jtextpane performance? Thx

0 投票
1 回答
514 浏览

java - 将内联 JComponents 插入到 JTextPane 中?

我正在开发一个项目,该项目需要能够将 JComponents 以及普通文本插入到 JTextPane 中。目前,我正在使用 JTextPane.insertComponent(Component) 添加 JComponent,但是,它们似乎是零星添加的,没有真正的组织。我终于发现它在克拉所在的任何地方都插入了它,所以我尝试将它设置在文本的末尾。但是,当我执行时:

我收到一条错误消息,指出该位置无效。有没有一种简单或更好的方法将 JComponents 插入到 JTextPane 最后一行的末尾?

此外,如果上述可能,有没有办法改变 JComponent 与文本的其余部分内联的位置,例如居中内联?

0 投票
1 回答
2472 浏览

java - 将 JTextPane 样式设置为具有类似控制台的格式?

有没有办法让 JTextPane 中的文本看起来类似于控制台输出?我的意思是,基本上,每个字符的宽度如何相同,这样 ASCII 艺术或间距缩进之类的东西才能正常工作。

例如,目前,如果我输入“First”,然后输入 5 个空格,然后在新的一行输入“Second”,然后输入 4 个空格,这两行的结尾位置不同,所以如果这些空格后面有文本,文本不会对齐。

我不知道它是否会改变任何东西,但 JComponents 也将包含在 JTextPane 中。

0 投票
1 回答
4121 浏览

java - 如何正确打印出带有“text/rtf”内容的 JTextPane 的硬拷贝?

我正在尝试使用JTextPane.

结果在软件 PDF 打印机 (FreePDF XP) 上看起来不错,但是当打印到真正的打印机时,文本的格式化部分之间没有适当的空间。

编辑:我上传了一个示例输出(底部是扫描的打印输出)

示例 http://ompldr.org/vNXo4Zg/output.png

在我看来,Graphics 对象开始绘制 RTF 代码的各个部分存在问题。好像它无法确定正确放置每个部分的位置(X 坐标)。

我是否必须提供某种坐标系转换?

使用的简单测试代码:

0 投票
4 回答
14894 浏览

java - 在不让用户编辑的情况下将文本添加到 JTextPane?

因此,我创建了自己的文本窗格类(扩展 JTextPane),并使用下面的方法向其中添加文本。但是,窗格需要可编辑才能添加文本,但这也允许用户编辑窗格中的内容。

谁能告诉我如何在不让用户操作的情况下将文本添加到窗格中?

0 投票
3 回答
97134 浏览

java - JTextPane 附加一个新字符串

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

我试过这个:

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

为什么会这样???

0 投票
2 回答
4466 浏览

java - 摆动中的彩色 xml 显示

是否有一种“简单”的方法可以通过 JEditorPane 或 JTextPane 以彩色/突出显示的方式向用户显示 xml 数据?