Sign in to follow this  
hisDudeness

easy Java fixes

Recommended Posts

hisDudeness    199
Hey I'm writing a Java applet and am trying to override some of the default behavior of the JButton controls. I want a JButton to be capable of displaying a Unicode character (say some Japanese character -- it doesn't really matter) on its label, and when selected, to draw that character to a JTextField. So we have the simple code: JButton b1 = new JButton(/* some unicode character */); JTextField t1 = new JTextField(1); (1) How do I specify "some unicode character" in the JButton's initialization? (2) What code would I use in the handler to update the text field with this same character?

Share this post


Link to post
Share on other sites
Zahlman    1682
If it expects a character value, you can use '\uXXXX', where the XXXX are four hex digits specifying the character; or similarly 0xXXXX. For a string, use double quotes instead of single quotes.

In the handler, you would have to ask the button for its label, and sent it to the text field. The best way to find out the necessary "magic words" is to read the API documentation (you can find it easily on java.sun.com).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this