aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JEditorPane" Watch "JEditorPane" New topic
Author

JEditorPane

Asanga Pradeep
Greenhorn

Joined: Apr 01, 2005
Posts: 5
is it possible to display text of different fonts (in differnet languages) in the same jeditor pane? locale is not available for these languages yet.
help pls thanks asanga
Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243
Hi,

Yes, it is possible to display different fonts, colours and styles at the same time.

I've not had a reason to do different languages at the same time, but these would be possible too. For example, chinese and english in the same editor should be possible.

I would start with this tutorial to get your imagination going, and run the sample webstart application:

http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

Cheers, Jared.
[ June 02, 2005: Message edited by: Jared Cope ]

SCJP 1.4 91%, SCJP 1.5 88%, SCJD B&S
Asanga Pradeep
Greenhorn

Joined: Apr 01, 2005
Posts: 5
Hi,

No, can't be done simply by setting the content type.

What you will need to do is to have various styles set up and then insert the text into the Document object model associated with the EditorPane using those styles to get the different looks.

For example, in a class extending DefaultStyledDocument you might define a chinese style such as:


code:
--------------------------------------------------------------------------------

Style chineseStyle = addStyle("chinese", null);StyleConstants.setFontSize(chineseStyle, fontSize);StyleConstants.setFontFamily(chineseStyle, "chinese capable font");StyleConstants.setForeground(chineseStyle, Color.BLUE.darker());StyleConstants.setBackground(chineseStyle, Color.YELLOW);

--------------------------------------------------------------------------------



and then an english style such as:


code:
--------------------------------------------------------------------------------

Style englishStyle = addStyle("english", null);StyleConstants.setFontSize(englishStyle, fontSize);StyleConstants.setFontFamily(englishStyle, "arial");StyleConstants.setForeground(englishStyle, Color.BLACK);StyleConstants.setBackground(englishStyle, Color.WHITE);

--------------------------------------------------------------------------------



And when you wish to enter in chinese onto the editor, you would need to do something like this (called from in your editor class):


code:
--------------------------------------------------------------------------------

...DefaultStyledDocument doc = (DefaultStyledDocument)getDocument();doc.insertString(characterPos, "your string", doc.getChineseStyle());...

--------------------------------------------------------------------------------



You will have to decide when to use which style within the logic of your application, but these are the basic ideas.

Hope you are able to get somewhere.

Cheers, Jared.
--------------------

SCJP 91%


====================================================================
this didnt' work i think it only works for JTextPanes when i use it on a JEDitorPane it gave a classcast exception so can any one help pls
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JEditorPane