Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to Display UTF-8 Characters in SWT?
How to Display UTF-8 Characters in SWT? [message #509686] Sun, 24 January 2010 18:24 Go to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: January 2010
Junior Member
Is it possible to display UTF-8 characters in SWT?
I tried
	Text text = new Text( shell, SWT.BORDER );
	Font font = new Font( display, "UTF-8", 20, SWT.NORMAL );
	text.setFont( font );
	String s = "\u8118";
	text.setText( s );

but it doesn't work.

[Updated on: Sun, 24 January 2010 18:25]

Report message to a moderator

Re: How to Displaying UTF-8 Characters in SWT? [message #509717 is a reply to message #509686] Mon, 25 January 2010 08:03 Go to previous messageGo to next message
Viliam Durina is currently offline Viliam DurinaFriend
Messages: 13
Registered: July 2009
Junior Member
I never had to worry about character set. All strings in Java are UTF-16, and I guess what you type correctly in UTF-16 get's displayed correctly.
If \u8118 is byte-encoded UTF-8 string, you should try this:

String s = new String(new byte[] { (byte)0x81, 0x18 }, "utf-8")

Viliam

babspam@hotmail.de wrote / napísal(a):
> Is it possible to display UTF-8 characters in SWT?
> I tried
>
> Text text = new Text( shell, SWT.BORDER );
> Font font = new Font( display, "UTF-8", 20, SWT.NORMAL );
> text.setFont( font );
> String s = "\u8118";
> text.setText( s );
>
> but it doesn't work.
Re: How to Displaying UTF-8 Characters in SWT? [message #509759 is a reply to message #509686] Mon, 25 January 2010 10:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33264
Registered: July 2009
Senior Member
Note that "UTF-8" is not the name of a font. You'll need to specify the
name of a font that supports the full range of characters you wish to
display. You might need to install such fonts so check other editors
on your OS for the font they're using.

babspam@hotmail.de wrote:
> Is it possible to display UTF-8 characters in SWT?
> I tried
>
> Text text = new Text( shell, SWT.BORDER );
> Font font = new Font( display, "UTF-8", 20, SWT.NORMAL );
> text.setFont( font );
> String s = "\u8118";
> text.setText( s );
>
> but it doesn't work.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to Displaying UTF-8 Characters in SWT? [message #509883 is a reply to message #509759] Mon, 25 January 2010 16:35 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: January 2010
Junior Member
The goal was to display classical greek letters, wich utf-8 code position is 1F00 to 1FFF (sorry, 8118 was wrong, it's decimal). This letters are part of the UTF-8 encoding. I don't want special fonts if possible.
Re: How to Displaying UTF-8 Characters in SWT? [message #509920 is a reply to message #509883] Mon, 25 January 2010 18:59 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

babspam@hotmail.de wrote:
> The goal was to display classical greek letters, wich utf-8 code
> position is 1F00 to 1FFF (sorry, 8118 was wrong, it's decimal). This
> letters are part of the UTF-8 encoding. I don't want special fonts if
> possible.

As Ed mentions, UTF specifies characters ... think ascii 65 == 'A' but
says nothing about how 'A' should be displayed (Courier, Times Roman,
etc) in your terminal or UI. Your font will. You need to make sure
that your app defaults to a common font that can display characters in
that range.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: How to Displaying UTF-8 Characters in SWT? [message #510048 is a reply to message #509920] Tue, 26 January 2010 06:02 Go to previous messageGo to next message
RealName Mising name is currently offline RealName Mising nameFriend
Messages: 7
Registered: July 2009
Junior Member
Paul Webster wrote:
> babspam@hotmail.de wrote:
>> The goal was to display classical greek letters, wich utf-8 code
>> position is 1F00 to 1FFF (sorry, 8118 was wrong, it's decimal). This
>> letters are part of the UTF-8 encoding. I don't want special fonts if
>> possible.
>
> As Ed mentions, UTF specifies characters ... think ascii 65 == 'A' but
> says nothing about how 'A' should be displayed (Courier, Times Roman,
> etc) in your terminal or UI. Your font will. You need to make sure
> that your app defaults to a common font that can display characters in
> that range.
>
> PW
>
Re: How to Displaying UTF-8 Characters in SWT? [message #510050 is a reply to message #509920] Tue, 26 January 2010 11:03 Go to previous messageGo to next message
RealName Mising name is currently offline RealName Mising nameFriend
Messages: 7
Registered: July 2009
Junior Member
Paul Webster wrote:
> babspam@hotmail.de wrote:
>> The goal was to display classical greek letters, wich utf-8 code
>> position is 1F00 to 1FFF (sorry, 8118 was wrong, it's decimal). This
>> letters are part of the UTF-8 encoding. I don't want special fonts if
>> possible.
>
> As Ed mentions, UTF specifies characters ... think ascii 65 == 'A' but
> says nothing about how 'A' should be displayed (Courier, Times Roman,
> etc) in your terminal or UI. Your font will. You need to make sure
> that your app defaults to a common font that can display characters in
> that range.
>
> PW
>
Try:

for (FontData fontData : display.getFontList(null, false)) {
System.out.println(fontData.getName());
}
for (FontData fontData : display.getFontList(null, true)) {
System.out.println(fontData.getName());
}

this should give you the list of fonts alredy installed in your system.
then you'll have to try which one displays correctly like this:


Font font = new Font( display, fontData.getName(), 20, SWT.NORMAL );
Re: How to Displaying UTF-8 Characters in SWT? [message #510666 is a reply to message #509883] Thu, 28 January 2010 05:04 Go to previous messageGo to next message
Viliam Durina is currently offline Viliam DurinaFriend
Messages: 13
Registered: July 2009
Junior Member
Forget about fonts, it's not about them. Just write the text in UTF-16, as that's the encoding that java uses for all strings. If the default font contains that character, it should display. Otherwise you'll have to choose another font.

text.setText('\u1f00\u1f22\u1fXX');

Viliam

babspam@hotmail.de wrote / napísal(a):
> The goal was to display classical greek letters, wich utf-8 code
> position is 1F00 to 1FFF (sorry, 8118 was wrong, it's decimal). This
> letters are part of the UTF-8 encoding. I don't want special fonts if
> possible.
Re: How to Displaying UTF-8 Characters in SWT? [message #510670 is a reply to message #510666] Thu, 28 January 2010 10:17 Go to previous message
No real name is currently offline No real nameFriend
Messages: 3
Registered: January 2010
Junior Member
Thank you, with the font "Microsoft Sans Serif" it works.
Previous Topic:MS Excel like spreadsheet features
Next Topic:MenuItem doesn't send selection event the 2nd time around
Goto Forum:
  


Current Time: Thu Dec 26 14:20:03 GMT 2024

Powered by FUDForum. Page generated in 0.03630 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top