Tag: jtextpane

JTextPane阻止在父JScrollPane中滚动

我有以下“树”的对象: JPanel JScrollPane JPanel JPanel JScrollPane JTextPane 当使用鼠标滚轮滚动外部JScrollPane我遇到一个恼人的问题。 一旦鼠标光标触及内部JScrollPane,似乎滚动事件就会传递到JScrollPane中,并且第一个不再处理。 这意味着滚动“父”JScrollPane停止。 是否可以仅禁用内部JScrollPane上的鼠标滚轮? 或者更好的是,如果没有要滚动的内容(大多数情况下textpane只包含1-3行文本),则禁用滚动,但如果有更多内容则启用它?

如何允许用户使用JComboBox在JTextPane中更改其字体?

我发现当谈到JTextPanes的主题时,缺乏互联网上有用的文档/教程。 我正在尝试做一个简单的文本处理器,我希望它能够从JComboBox中选择一个字体系列,该字体系列根据用户在其系统上安装的字体填充自己。 但是,无论我尝试什么样的实验,我都无法弄清楚如何让它发挥作用。 我所拥有的是一个基于JTextPane构建的工具栏类。 目前,它有一堆样式按钮,用于设置对齐和粗体,斜体和下划线。 这是我的代码: /** * The StyleBar is used to customize styles in a Styled Document. It will take a * JTextPane as an argument for its constructor and then all actions to be taken * will affect the text in it. * * @author Andrew */ public class StyleBar extends JToolBar […]

Java JTextPane更改所选文本的字体

我有一个JTextPane(或JEditorPane,我可以使用任何问题)。 如何将所选区域的字体更改为特定字体? textpane.getSelectedText().setFont()不起作用。 (即使使用font-family)

如何在JTextPane中轻松编辑所选文本的样式?

如何在JTextPane中轻松编辑所选文本的样式? 这方面似乎没有太多资源。 即使你可以指导我找到一个很好的资源,我也会非常感激。 另外,如何获取所选文本的当前样式? 我试过styledDoc.getLogicalStyle(textPane.getSelectionStart()); 但它似乎没有起作用。

如何在JtextPane中设置行间距?

首先,我像这样设置JTextPane: HTMLEditorKit editorKit = new HTMLEditorKit(); HTMLDocument document = (HTMLDocument) editorKit.createDefaultDocument(); JTextPane textPane = new JTextPane(); textPane.setContentType(“text/html”); textPane.setDocument(document); 我想在JtextPane中设置行间距,这是我的想法,但它无法工作: SimpleAttributeSet aSet = new SimpleAttributeSet(); StyleConstants.setLineSpacing(aSet, 50); textPane.setParagraphAttributes(aSet, false); 我错了?

如何在JTextPane中实现项目符号?

我有一个带有StyledDocument和RTFEditorKit的JTextPane 。 如何在JTextPane上添加项目符号(最好是多级项目符号)?

更新时摇摆组件闪烁很多

我在某处有几千行代码,我注意到当我更新它时,我的JTextPane闪烁了……我在这里写了一个简化版本: import java.awt.*; import javax.swing.*; public class Test { static JFrame f; static JTextPane a; static final String NL = “\n”; public static void main(String… args) { EventQueue.invokeLater(new Runnable(){ public void run() { f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); f.setSize(400, 300); f.setLocationRelativeTo(null); a = new JTextPane(); f.add(new JScrollPane(a)); new Thread(new Runnable(){ public void run() { […]

如何修改JTextPane中的字母间距?

我需要修改JTextPane中的字母间距(字体跟踪),我无法让它工作。 当我使用JTextArea时,我可以这样做: Font font = new Font(“Courier New”, Font.PLAIN, 10); HashMap attrs = new HashMap(); attrs.put(TextAttribute.TRACKING, -0.1); font = font.deriveFont(attrs); textArea.setFont(font); 但由于我需要更改行间距,我需要使用JTextPane,并执行: textPane.setFont(font) 正如我对JTextArea所做的那样不起作用。 我试过的另一件事是: MutableAttributeSet set = new SimpleAttributeSet(); StyleConstants.setLineSpacing(set, -0.2); StyleConstants.setFontFamily(set,”Courier New”); StyleConstants.setFontSize(set, 10); set.addAttribute(TextAttribute.TRACKING, -0.1); ta.setParagraphAttributes(set, true); 但跟踪属性不起作用。 我究竟做错了什么?

在JTextpane中切换文本换行

我如何在JTextpane上切换文本换JTextpane ? public JFrame mainjFrame = new JFrame(“Text Editor”); public JTextPane mainJTextPane = new JTextPane(); public JScrollPane mainJScrollPane = new JScrollPane(mainJTextPane); mainjFrame.add(mainJScrollPane);

JTextPane不包装文本

我遇到了一个奇怪的问题。 我在JscrollPane中有一个JtextPane,它在分发列表中显示大字符串,并且在我使用eclipse运行程序时正确包装代码但是当我在使用java webstart运行相同程序时它停止包装文本。 你能告诉我该怎么办。 这是代码。 private JScrollPane displayResults(String distributionList) { // TODO Auto-generated method stub JTextPane textArea = new JTextPane(); textArea.setText(distributionList); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize( new Dimension( 500, 500 ) ); return scrollPane; }