Word wrapping in JTextPane

风格不统一 提交于 2019-12-10 19:19:29

问题


I have a word wrapping issue when using JTextPane. I think it's my IDE (JCreator) but when i use the source everyone else is using I get several errors. Sorry for the line breaks... Could it be my IDE or can someone please let me know the right way of doing this. TIA -Roland

The source I am using can be found at http://java-sl.com/tip_html_letter_wrap.html

lol.. I forgot the space! Thanks all. It is going to proceed. I have been programming all night and am a little groggy. Best of luck -Roland

> --------------------Configuration: inigui - JDK version <Default> - <Default>--------------------
> C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:283: error: ')' expected
>               gentextp.setEditorKit( newHTMLEditorKit(){ 
>                                                        ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:285: error: ';' expected
>            public ViewFactory getViewFactory(){ 
>                                             ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:330: error: illegal
> start of type
>         }); 
>          ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: <identifier> expected
>         panel.setLayout(new GridLayout(1, 1));
>                        ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: illegal
> start of type
>         panel.setLayout(new GridLayout(1, 1));
>                         ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: ')' expected
>         panel.setLayout(new GridLayout(1, 1));
>                            ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: ';' expected
>         panel.setLayout(new GridLayout(1, 1));
>                                       ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: illegal
> start of type
>         panel.setLayout(new GridLayout(1, 1));
>                                        ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: <identifier>
> expected
>         panel.setLayout(new GridLayout(1, 1));
>                                         ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: ';' expected
>         panel.setLayout(new GridLayout(1, 1));
>                                          ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: illegal
> start of type
>         panel.setLayout(new GridLayout(1, 1));
>                                            ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:337: error: <identifier>
> expected
>         panel.setLayout(new GridLayout(1, 1));
>                                             ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:339: error: illegal
> start of type
>         return panel;
>         ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:339: error: ';' expected
>         return panel;
>               ^ C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:341: error: class, interface, or enum expected }  ^ 15 errors

回答1:


The linked code needs space chars in 3 places to compile.

E.G.

final JEditorPane htmlTextPane = newJEditorPane(); 

should be:

final JEditorPane htmlTextPane = new JEditorPane(); 

Look at the line numbers identified by the compiler for the others.




回答2:


You are missing a white space after the new keyword:

gentextp.setEditorKit( newHTMLEditorKit(){

should be

gentextp.setEditorKit( new HTMLEditorKit(){

See how syntax coloring changes between the two?




回答3:


I tried the linked source myself and it work fine (Eclipse)

However, based on the error message you pasted here, you are clearly not using (exactly) using this code.

Apparently, your compiler has issues on the following lines:

C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:283 C:\ucdhb2\gaia\inigui\inigui2\src\inigui.java:285 ...

I recommend to revise the correct usage of the brackets, semicolons, etc.

If you still have issues, please post YOUR code.



来源:https://stackoverflow.com/questions/12894526/word-wrapping-in-jtextpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!