【问题标题】:Edit the text selected in JtextPane编辑在 JtextPane 中选择的文本
【发布时间】:2012-11-06 00:35:41
【问题描述】:

我有两个 Jtextpane 我想要做的是我从 1 个 Jtextpane 中选择文本,并且我希望它应该在选择菜单项 Edit 后出现在第二个 Jtextpane 中

我做过的

 popMenu[i].addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String str = e.getActionCommand();
                   .....
                        if (str.equalsIgnoreCase("edit")) {
                            taSecond.setBackground(new Color(0xFBFCDD));
                            taSecond.setText(taFirst.getSelectedText());
                            System.out.println("bounds====>"+taFirst.getBounds());
                            taFirst.getBounds().setBounds(taFirst.getBounds());
                            editedText = true;

                        }
                    }
                });

现在我不知道如何将编辑后的文本放回从我获得文本的位置选择的位置 谁能告诉解决方法

【问题讨论】:

  • 想知道你期望它做什么:taFirst.getBounds().setBounds(taFirst.getBounds());... 它完全没有任何作用。

标签: swing edit jtextpane


【解决方案1】:

谢谢

try {

                    doc.remove(start, end-start);
                    doc.insertString(start, str, normal);
                    editedText=false;
                } catch (BadLocationException ex) {
                    Logger.getLogger(ChatPane.class.getName()).log(Level.SEVERE, null, ex);
                }

【讨论】:

  • 现在我想要的是如何更改所选文本区域的背景颜色
  • 在您自己的答案上发布另一个问题而不是 cmets。看看this questionthis one
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-01
  • 2022-11-22
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
相关资源
最近更新 更多