English 中文(简体)
在JEditorPane实施正本案文
原标题:Implementing on-the-fly text styling in a JEditorPane
  • 时间:2009-09-28 20:39:23
  •  标签:

我的想法是,在 Java撰写一份说明书,其中某些简单的文字替代与你一样;或许是Markdown syntax的一小部分。 例如,如果你进入一条直截了当的线,就会:

sometext

Wikidpad是Im试图做的事的一部分(Im 不仅只是执行,只是 s子/显示功能的一部分)。

So essentially I m looking for a way to write some kind of component that, when the user hits "return," it will look at the line entered and do any magic it needs to do to get the html tags right.

我先把我的头指针放在文件、文件夹和文件“生命”和“超声”面前,这样,没有人会把我带上正确的道路?

最佳回答

您感兴趣的是:java 文本编辑资料袋。 这位教授是伟大的,帮助我执行一个与你的问题相似的传教士。 专为处理你的问题而设计的剪辑包(或不是)。 我写了一种充满活力的维系,如利用这一技术连接系统,尽管没有太多的斗争。 在此,我必须做的是:

  1. Make a Document The first task is to create a document model that tags the pattern when it identifies the text. If you look at the JavaDocument in the linked example there is an insertUpdate call. In the document you can find the pattern you are looking for and replace it with a custom style appropriate. Essentially you just create a style and apply it to the document where the pattern is matched. An alternative to the update method is to make this use a private worker thread to periodically scan for new wiki content.

  2. www.un.org/Depts/DGACM/index_spanish.htm A. 构建一种成因: 在你的模式完成后,你可以实施一种背景,形成一种适合提出新案文的观点。 在相关例子中,它们提供了一种风格。 这样做是为了使案文得到考虑。 在这里,你可以制定规则,找到你的具体主角,并像强调的那样,删除方括号。

  3. <Make an Editor Tool 这将混淆一切,确定贵文件的内容类型。

保存文件并视具体情况是好事,你可以把文件附在两种观点上,一种是简单文本,另一种是新习俗。 由于缺省风格的确不承认你的标签,它应该以原始维系代码的形式显示。 新的观点将把这一看法转化为适当的联系。

我希望这一帮助。 不幸的是,这种 st势是复杂的,甚至wing。 亲爱!

问题回答

如你需要做的那样,在你们的编辑部分执行某种关键听众,在他们进入文字领域之前审查关键的中风。 然后,它可以在缓冲地带进行搜索,发现你的控制特征,并做它所需要的事。

我没有像日本这样多的经验。 但我认为,你可以像任何其他方面一样,给他们增加关键的听众。

基本上,我不认为存在这样的一个组成部分,因此,你基本上需要自己执行。

但我可能错了。

它们在进入时,或者在提交数据时,是否必须发生?

如果报告提交,则等待它们发布一个可节省数据的纽扣吨,然后是JEditorPane.getText()、“固定”文本,以及JEditorPane.setText(文本);

Okay, if it should be on the fly, try adding an Input Method Listener. InputMethodEvent should be able to call "getText()", and you should be able to parse for this after every keypress. If you want to do it after every time the user hits enter, get the text on every keypress, and see if the current location in the text is one character after an , or similar.

首先,我建议使用JTextPane,因为这更适合对文本适用风格。 接着,非常容易增加一项关键的活动:

jTextPane1.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(java.awt.event.KeyEvent evt) {
        jTextPane1KeyPressed(evt);
    }
});

private void jTextPane1KeyPressed(java.awt.event.KeyEvent evt) {
    // TODO add your handling code here:
    String txt = jTextPane1.getText();

}

上述法典很容易由净户产生。

那么,你可以采取类似做法的风格:

StyledDocument doc = jTextPane1.getStyledDocument();
Style style = jTextPane1.addStyle("Bold", null);
StyleConstants.setBold(style, true);

int pos, endpos;
// Find pos of word to be displayed in bold
...

// Set style
doc.setCharacterAttributes(pos, endpos, style, true);

http://fifesoft.com/rsyntaxtextarea/“rel=“nofollow noretinger”>RSyntaxTextArea,它做了你需要的事情,你可以添加自己的灵活性/规则。





相关问题
热门标签