- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该问题似乎与 this one 重复但事实并非如此。因此,在否决这个问题之前,请澄清是否有任何混淆。
我想在我的 JTextPane
中每 6-7 行后绘制一条水平线 我正在使用 StyledDocument
并将字符串插入到我的 JTextPane
在运行时。像这样的东西:
String myStr = "Some program-generated text";
doc.insertString(doc.getLength(), myStr, attributeSet);
现在如何每隔几行画一条水平线?我试过了
JTextPane textPane = new JTextPane();
textPane.setContentType("text/html");
textPane.setText("<html>Some Text Above The Line<hr size=5>Some Text Below</html>");
但目前我的应用程序使用 setContentType("text/plain");
将其更改为 Text.html
会扰乱整个 UI。此外,如果我使用 SetText()
然后它将作为新文本插入,所有以前的文本都将消失,我附加了 doc.insertString();
/p>
如有任何帮助,我们将不胜感激。
最佳答案
像这样!?
首先创建您自己的 JTextPane 子类。实现 draw 方法并使用 Graphics Context 中的 FontMetrics 来获取文本的高度。
public class MyTextPane extends JTextPane {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(new Color(255, 0, 0, 128));
FontMetrics fm = g2.getFontMetrics();
int textHeight = fm.getHeight();
for (int i = textHeight; i < getHeight(); i += (6 * textHeight)) {
g2.drawLine(0, i + 1, getWidth(), i + 1);
}
g2.dispose();
}
}
关于java - 在 JTextPane 中绘制水平线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25535277/
我正在序列化一个 JTextPane 的 Document,以便将其样式化的文本保存到数据库中。我有一个 caretListener 附加到 JTextPane 我想知道序列化这个 Document
我目前正在尝试制作 Log4j 2登录 JTextPane .它应该像 Netbeans IDE 控制台中的 STDERR 或 STDOUT(包括文本样式 - 颜色)。 我知道我需要创建一个 appe
我在 JScrollPane 中有一个 JTextPane(水平策略从不,垂直策略始终)。我编写了一种在此 JTextPane 中附加文本的方法。现在有一个按钮,单击该按钮时,操作监听器正在运行,执行
我有一个 JTextPane (1),旁边还有另一个 (2)。我已经同步它们,如果在(2)中输入一行,则在(1)中输入一行,但是当我插入图像(24px)时,(2)会自动调整行长度,但(1)当然不会调整
当我使用 JTextPane 并在 HTML 编辑器模式下键入一些文本时 JTextPane textPane = new JTextPane(); textPane.setContentType("
我在 java swing 中有一个应用程序包含 JTextPane 和 HTMLDocument。假设我将 Pane 的文本设置为:
有没有办法读取 JTextPane 的内容逐行?很像 BufferedReader? 最佳答案 Element root = textPane.getDocument().getDefaultRoot
这是我的问题。我正在编写一个具有语法突出显示的编辑器。没什么特别的,但它可以完成工作。问题是我正在实现错误识别,当我想添加样式来下划线时,我覆盖了我以前的样式。这是一个屏幕截图: 我正在做这样的事情来
所以我想写一个简单的编辑器。我想将所有字符之间的所有字符都涂成灰色“字符。它的片段是: class MainPanel extends JPanel { private int WIDTH = 800
我正在开发一个应用程序,当我从列表中选择一个值(文件)时,它应该在不同形式的 jTextPane 中打开。我正在使用两个面板,一个是显示我的列表的主面板,一个是 ExcelSheet,当我单击列表值时
我创建了一个使用 JTextPane 的 Swing 界面。 JTextPane 使用自定义颜色突出显示: textPane.getHighlighter().addHighlight(startPo
有没有办法使 JTextPane 中的文本看起来与控制台输出的文本相似?我的意思是,基本上,每个字符如何具有相同的宽度,以便 ASCII 艺术或间距缩进等内容可以正常工作。 例如,目前,如果我输入“F
我没有得到垂直滚动条。滚动JTextPane。我正在使用 JPanel 显示 JScrollPane 内部的 JTextPane。这是代码。请查看。谢谢。 import java.awt.*; imp
尝试使用此代码,但它不能准确地改变颜色,请注意“停止”一词。当您键入单词时就会发生这种情况。 https://stackoverflow.com/a/28773736/7694892 最佳答案 在我看
我正在尝试用 JScrollPane 包装 JTextPane,并且我需要背景透明。 这是我的代码: public CharPanel(){ super.setLayout(null);
我使用两个语句添加了图像和文本。但在 JTextPane 中,它仅显示文本。我的代码如下 - jTextPane1.insertIcon(new ImageIcon("t.png")); jTextP
我有两个具有静态大小的 JTextPanes,我想像文本处理器中的两个页面一样连接它们。如果我在第一个 JTextPane(页面)中写入一些内容,并且对于一个 JTextPane 来说太长,那么它会溢
我有一个 JTextPane,其模型是 DefaultStyledDocument。我注意到,如果显示文本,然后使用 setCharacterAttributes 将一行上的每个字符更改为更大的字体,
我有来自 Netbeans 设计器部分的 JTextPane。我想在其上添加列和行。但是,JTextPane 的属性窗口中没有添加列或行的选项。还有其他方法可以做到这一点吗? 最佳答案 JTextPa
我有一个文本需要格式化,文本的第一个单词需要加粗、大字体并居中。 为了进行这种格式化,我使用了 TextSamplerDemo.java 中的解决方案在 JTextComponents 的 oracl
我是一名优秀的程序员,十分优秀!