Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3496 > unrolled thread
| Started by | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:45 +0000 |
| Last post | 2011-04-27 15:45 +0000 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.java.gui
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Can't display UTF-8 e "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Can't display UTF-8 e "jgricourt" <jgricourt@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Can't display UTF-8 e "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Can't display UTF-8 e "tar" <tar@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Can't display UTF-8 e "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Can't display UTF-8 e "jgricourt" <jgricourt@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
| From | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Subject | Re: Can't display UTF-8 e |
| Message-ID | <482afd9b$0$2492$da0feed9@news.zen.co.uk> |
To: comp.lang.java.gui
jgricourt@free.fr wrote:
> Hello,
>
> I am trying to display unicode text in a JLabel, unfortunately the
> snippet code right below will fail ... (the JLabel displays it as
> ISO-8859-1).
Your posting is encoded in 8859-1 too. This doesn't help.
>
> new JLabel(new String("|-|-|-|-|-".getBytes("UTF-8")))
>
> Any idea / suggestions ?
Assuming you want a row of e with acute accent, set your IDE or editor
to UTF8 and then type in
------------------------- 8< ------------------------------
public class CharacterEncodingTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new CharacterEncodingTest();
}
});
}
CharacterEncodingTest() {
JPanel p = new JPanel();
p.add(new JLabel("|-|-|-|-|-"));
JFrame f = new JFrame("Char Encoding Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
------------------------- 8< ------------------------------
The above works for me.
If I have my newsreading software set correctly, this posting will be
encoded in UTF-8 and all will be well.
You can always avoid most charset/encoding issues by doing something like
new JLabel("\u00e9\u00e9\u00e9\u00e9\u00e9");
If I have misunderstood your question you'd best spell out in words what
characters you types in, what you expected to see and what you actually saw.
The key really is to make sure your IDE/editor is set to use UTF-8.
--
RGB
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "jgricourt" <jgricourt@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <f1be58a9-aa85-4900-a781-2ebba6655e76@8g2000hse.googlegroups.com> |
| In reply to | #3496 |
To: comp.lang.java.gui Your example works for me too ! But unfortunately this is not what I am trying to do. I got a text string from a UTF-8 encoded file and after reading the file I set a String with the text content in order to display in a JLabel. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <5buo249qivgefm50kqm6gjfuuhpad2tkho@4ax.com> |
| In reply to | #3499 |
To: comp.lang.java.gui On Thu, 15 May 2008 06:34:12 -0700 (PDT), jgricourt@free.fr wrote, quoted or indirectly quoted someone who said : >Your example works for me too ! But unfortunately this is not what I >am trying to do. I got a text string from a UTF-8 encoded file and >after reading the file I set a String with the text content in order >to display in a JLabel. You must partition your problem. 1. make sure the file truly is encoded it UTF-8. See http://mindprod.com/jgloss/encoding.html and use the encoding recogniser. 2. read the UTF-8 file. See http://mindprod.com/applet/fileio.html 3. verify that you indeed have the Unicode chars expected by dumping them in decimal or hex. 4. make sure the font you are using supports those characters. See http://mindprod.com/applet/fontshower.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "tar" <tar@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <ymi1w43v8yp.fsf@blackcat.isi.edu> |
| In reply to | #3499 |
To: comp.lang.java.gui jgricourt@free.fr writes: > Your example works for me too ! But unfortunately this is not what I > am trying to do. I got a text string from a UTF-8 encoded file and > after reading the file I set a String with the text content in order > to display in a JLabel. Do you actually have a text string? Or just an array of bytes? I would have thought that any string you get back from reading the UTF-8 file would be a proper Java 16-bit Unicode string. Why isn't it? How do you get your text string? -- Thomas A. Russ, USC/Information Sciences Institute --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <dMqdnZfX7Zd_G7HVRVnyjgA@bt.com> |
| In reply to | #3499 |
To: comp.lang.java.gui
jgricourt@free.fr wrote:
> Your example works for me too ! But unfortunately this is not what I
> am trying to do. I got a text string from a UTF-8 encoded file and
> after reading the file I set a String with the text content in order
> to display in a JLabel.
>
Your Google-fu is too weak! Exercise it more!
--------------------------- 8< ---------------------------------
class CharacterEncodingTest {
static final String FILENAME = "foo.txt";
public static void main(String[] args) {
try {
writeMyUtf8File(FILENAME, "|-|-|-|-|-");
final String text = readMyUtf8File(FILENAME);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new CharacterEncodingTest(text);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
static void writeMyUtf8File(String name, String text)
throws IOException {
FileOutputStream fos = new FileOutputStream(name);
Writer osr = new OutputStreamWriter(fos, "UTF-8");
osr.write(text);
osr.close();
}
static String readMyUtf8File(String name) throws IOException {
FileInputStream fis = new FileInputStream(FILENAME);
InputStreamReader isr = new InputStreamReader(fis, "UTF8");
BufferedReader br = new BufferedReader(isr);
String text = br.readLine();
br.close();
return text;
}
CharacterEncodingTest(String text) {
JPanel p = new JPanel();
p.add(new JLabel(text));
JFrame f = new JFrame("Char Encoding Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
--------------------------- 8< ---------------------------------
--
RGB
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "jgricourt" <jgricourt@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <1e9d5665-41dd-4ea9-bedd-be1c1e985b41@b1g2000hsg.googlegroups.com> |
| In reply to | #3504 |
To: comp.lang.java.gui OK I admit my example was flawed. The text string really came from a ressource bundle file (UTF-8 encoded of course) using the standard ressource bundle API. Anyway many thanks RGB, your last example was very inspiring. JGG --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web