Skip to main content

Underline single character in AWT Text/Label - works on Linux but not Win?

4 replies [Last post]
misha680
Offline
Joined: 2008-10-03

Dear All:

I am trying to underline a single character in, say, a button label.

This seems to work fine using a Unicode trick in Linux but not on Windows. Any ideas why?

Thank you
Misha

<br />
    public void setShortcut(char shortcut) {<br />
	String label=getLabel();<br />
	label=label.replace(Character.toString(shortcut),Character.toString(shortcut)+"\u0332");<br />
	setLabel(label);<br />
    }<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
anthony_p
Offline
Joined: 2006-07-24

Ah, yes. There are some problems with Unicode support on Windows unfortunately. To name a few: 6543928, 6515107, 6339489, and probably some others (you may find them on the http://bugs.sun.com/). Sorry, but these aren't fixed yet.

anthony_p
Offline
Joined: 2006-07-24

Such functionality does not exist in AWT. You may, however, use a Swing JLabel or Swing text controls - they have some basic support for html text formatting so that you can set the label text to something like:
[code]
Underline me! Yay!
[/code]

misha680
Offline
Joined: 2008-10-03

Actually this works fine in Linux:

[code]
package com.mksoft.fbbday;

import java.awt.*;
import java.awt.event.*;

public class SuperButton extends Button {
public SuperButton(String label) {
super();
if (label.contains("&")) {
int idx=label.indexOf("&");
char shortcut=label.charAt(idx+1);
setLabel(label.replace("&",""));
setShortcut(shortcut);
} else {
setLabel(label);
}
}

public void setShortcut(char shortcut) {
String label=getLabel();
label=label.replace(Character.toString(shortcut),Character.toString(shortcut)+"\u0332");
setLabel(label);
}
}
[/code]

Its a proper Unicode character so why not Windows?

p.s. Try it on Linux if don't believe me :)

misha680
Offline
Joined: 2008-10-03