【问题标题】:I need help updating my JTextPane by adding a strikethrough [duplicate]我需要通过添加删除线来更新我的 JTextPane [重复]
【发布时间】:2015-07-30 16:26:36
【问题描述】:

我正在开发用户界面,我在JPanelJTextPane 中有一个JTextPane,我使用JTextPane.getStyledDocument().insertString() 添加了字符串。现在我想更新JTextPane 并在这些词中打上一个删除线。

单击JButton 后如何更新单词?我不希望 JTextPane 中的所有字符串都被删除,只是某些字符串。

【问题讨论】:

    标签: java swing user-interface jtextpane strikethrough


    【解决方案1】:

    在 jButton 的 actionListener 中试试这个。

    jTextPane.setContentType( "text/html" );
    jTextPane.setText("<strike> Words to strike </strike> Words not to Strike");
    

    用你的逻辑敲击所需的单词。

    您可以使用jTextPane.getSelectedText()jTextPane.getText();

    【讨论】:

    • OP 要求删除JTextPane 中的特定词
    • 感谢 RealSkeptic ! @OP 这个可以吗?
    • 它确实删除了它。现在我要解决某些要罢工的词的逻辑。非常感谢!
    • @realSkeptic 我会尝试找出如何敲击特定的单词,如果我生病了,请告诉你们。非常感谢
    • 很高兴为您提供帮助!如果您的问题得到解决,请接受答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    相关资源
    最近更新 更多