[jruby-user] Fwd: Fwd: utf-8 or unicode on Swing jlabel

125 views
Skip to first unread message

Manuel Ramos Caro

unread,
Jul 14, 2012, 10:49:57 PM7/14/12
to us...@jruby.codehaus.org

Hi...

 I try to print a utf-8 string into a jlabel but it's not readeable... but when i put to console all are ok... any idea of a solution ...




Manuel Ramos Caro

unread,
Jul 18, 2012, 8:18:11 PM7/18/12
to us...@jruby.codehaus.org
Hi.

After a hard study of the problem i think that the better solution is convert from UTF-8 to Java Unicode escape sequence...

It's look like...

"\xC3\xB1" --conversion--> "\u00F1"

...and then past it to the Jlabel...any Jruby example for this out there...???

The idea is to convert any utf-8 char to it Java Unicode Escape value for multilingual support...

I'm migrating a Open Source GUI from Shoes to Jruby and Swing....

Thanks...

Manuel Ramos Caro

unread,
Jul 25, 2012, 8:48:05 PM7/25/12
to us...@jruby.codehaus.org
Hi, again...

After  study and a hard work i think that i have a solution on Windows and Linux...

I write a class that's reencode the sequence on a new sequence of chars and then return it as java string... on Windows an aditional work must be done an unicode font on must be set the Jlabel...

¿Any Open source font out there?
¿Any sugestion or corrections for this class?

Regards.
Manuel Ramos Caro


class UnicodeEscape
  def initialize(string)
       @string = '\\u'+ string.unpack("U*").map{|c|"%04x" %c}.join('\\u')
       puts "transformed ucode string: " + @string.to_s
       @string_out = java.lang.StringBuilder.new
       i = 0
       @string.split('\u').each do |piece|  
            if i > 0  
               puts "char " + i.to_s + " :" + piece 
               @char = java.lang.Character.new java.lang.Integer.parseInt(piece, 16).to_java(:char)
               puts "char " + i.to_s + " :" + @char.to_s
               @string_out.append(@char)  
            end #if i > 0
            i += 1
       end #@string.split('\u').each do |piece|
      
       puts "output string: " + @string_out.toString.to_s
  end #def initialize(string)
  def return_unicode_escape
       return @string_out.toString
  end #def return_unicode_escape
end #class UnicodeEscape

Roger Gilliar

unread,
Jul 26, 2012, 3:02:49 PM7/26/12
to us...@jruby.codehaus.org
Hi,

I did a lot of Swing programming with JRuby and never had such problems. Could you post some sample code that shows your problem ?

Regards
  Roger

Manuel Ramos Caro

unread,
Jul 26, 2012, 5:19:14 PM7/26/12
to us...@jruby.codehaus.org
Thanks, the problem is solved i have tested this translation class and work for me... i must take a stream converted to UTF-8 with iconv and isn't posible to me to write a simple 'ñ' that latest Jruby puts ok on a linux console  using a Jlabel with setText source on that stream instead any usage of unicode scaped charset hardcoded work ok \\uxxxx... but after this translation i had a correct string to put on this label thats works ok... i have test it on windows and linux with chinesse chartset...and it's hard send you a complete example thats works...

This is the application...

http://sourceforge.net/projects/rmldonkey

...there's not any jruby out there i'm doing a initial transition...before commit any code on repo...

if you used a open source font that support a wide range of charset... that can help a little more.... i'm using a close one from MS on testing...

Regards
Manuel Ramos Caro.
Reply all
Reply to author
Forward
0 new messages