设置jeditorpane的字体和样式 [英] Setting the font and style of jeditorpane

查看:312
本文介绍了设置jeditorpane的字体和样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我的最后一个学习项目,我目前正在为该公司开发一个应用程序,并且在此应用程序中,该功能允许您打印论文,因此我显然使用了jeditorpane,并带有

I am currently developing an application for this company as my last year of studies project, and in this application there's this function that allows you to print a paper, so i used the jeditorpane obviously, with the Charles Bell HTMLEditorKit for the predefined functions like setting the font and printing, etc... and there's this pre-written text that i have to load from a text file and then the program is supposed to add some text inside the file automatically, and the user also is allowed to add more if he needs to, or change the font or style or whatever.

这就是问题所在,因为预定义的文本应该已经与已设置的字体对齐,并且已经具有其他属性,并且由于txt文件不允许这样做,所以我尝试使用docx文件,使文本在编辑器窗格中变得难以理解,我也尝试了docx4j api,但是后来我没有HTMLEditorKit菜单和功能,(或者我可以,但我不知道如何),应用程序的执行变得很慢用这个API.我还尝试了这个中期编辑器工具包,发现它提供了很多功能,确实非常有用,但是我无法将文本文件加载到它的textpane中.

So here is the problem, since the predefined text should be already aligned with the font already set and some other properties already in place, and since the txt file doesn't allow that, i tried to use a docx file, which makes the text incomprehensible in the editorpane, i also tried the docx4j api, but then i wouldn't have the HTMLEditorKit menu and functions, (or maybe i could but i don't know how) and the execution of the app becomes rather slow with this api. I also tried this metaphase editor kit which i found it to be really useful with a lot of functions to offer, but i couldn't load a text file to it's textpane.

所以我的问题是: 1)如何使用查尔斯贝尔HTMLEditorKit并将docx文件加载到有问题的edtiorpane中? 2)或者我如何在带有功能菜单(样式,打印,字体...)或其他预定义菜单的HTMLEditorKit中使用docx4j api? 3)甚至更好的是,我如何仍然可以使用具有完整功能菜单的metaphaseEditorPane并同时在其文本窗格中加载现有的docx文件?

So my question(s) to be exact is(are): 1)How can i use the charles bell HTMLEditorKit and load a docx file into the edtiorpane in question? 2)Or how can i use the docx4j api with the HTMLEditorKit with the functions menu (style, print, font...) or maybe another predefined menu? 3)Or even better, how can i still use the metaphaseEditorPane with its full of functions menu and at the same time load an existing docx file in its textpane?

很抱歉,这个问题很长,如果有任何帮助,我都会非常需要并感激.

Sorry for the long question and any help would count, i would really need and appreciate it.

推荐答案

经过几天的搜索和测试,我终于找到了解决方案,事实证明这很简单.

I found finally the solution after days of searching and testing, It turns out to be very simple actually.

我要做的就是使用一个中期编辑器面板(顺便说一下,它有一个很棒的工具栏),创建一个DocxEditorkit,然后将中期编辑器面板的文本窗格的editorkit设置为此DocxEditorKit,尽管该变体可以处理HTML文本.窗格,它奇迹般地起作用了……

All i had to do is use a metaphase editor panel, (which has a great toolbar by the way) create a DocxEditorkit and then set the editorkit of the metaphase editor panel's textpane to this DocxEditorKit, although the metamorphose works with HTML text pane, it miraculously worked...

DocxEditorKit DEK=new DocxEditorKit;
MetaphaseEditorPanel MEP=new MetaphaseEditorPanel;
MEP.getHTMLTextPane().setEditorKit(DEK);

   //Try and Catch blocks of course to read the file
DEK.read(new FileInputStream(PathToFile), MEP.getHTMLTextPane().getDocument(), 0);
getContentPane.add(MEP, BorderLayout.CENTER);

就是这样...谁认为这会如此简单.

And that was it... Who thought it would be as simple as this.

这篇关于设置jeditorpane的字体和样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆