- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于我们一开始就走错了路,我再问一遍,之前的问题被删除了。请检查一下,JTextPane 的边框与 JTextArea 的边框不一样,不是默认的:
所以我需要一个看起来与 JTextArea 完全一样的 JTextPane。
我将 JTextPane 的边框设置为 new JTextArea().getBorder();。看起来应该是这样,但是焦点没有正确绘制...我该如何修复它?
我在这里使用 Nimbus,如果有帮助的话......
SSCCE:
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager.LookAndFeelInfo;
public class Main
{
public static void main(String[] args)
{
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
try
{
UIManager.setLookAndFeel(info.getClassName());
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e)
{
System.out.println("No Nimbus!");
}
break;
}
}
JFrame a = new JFrame("Test");
a.setSize(200, 400);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a.getContentPane().setLayout(new BoxLayout(a.getContentPane(), BoxLayout.Y_AXIS));
JTextPane[] b = new JTextPane[5];
for (int i = 0; i < 5; i++)
{
b[i] = new JTextPane();
b[i].setBorder(new JTextArea().getBorder());
b[i].setText(Integer.toString(i));
a.getContentPane().add(b[i]);
}
a.setVisible(true);
}
}
我已将边框设置为与 JTextArea 上的边框相同,但焦点未正确绘制或移动。如果您注释掉该行,则不会有任何边框。
最佳答案
如果您添加一个强制重新绘制的焦点监听器,那么奇怪的行为就会消失。
示例:
for (int i = 0; i < 5; i++) {
final JTextPane b = new JTextPane();
b.setBorder(new JTextArea().getBorder());
b.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent arg0) {
b.repaint();
}
@Override
public void focusLost(FocusEvent arg0) {
b.repaint();
}
});
b.setText(Integer.toString(i));
a.getContentPane().add(b);
}
这看起来像是一个黑客修复,但我不确定为什么会发生这种情况。
关于java - 看起来像 JTextArea 的 JTextPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19456073/
我正在序列化一个 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
我是一名优秀的程序员,十分优秀!