Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default unicode ok for text pane but not for button label

    I'm pretty sure I've read everything there is to read in this forum about unicode handling but have not found an answer to my particular problem. I've been pulling my hair out all day on this. I'm sure there is a simple solution I may have overlooked. Here are the details:

    I am developing a java app using netbeans 6.9.1. My main frame has a JTextPane in which I display plain text and some symbols. I have a button box with a number of buttons that, when clicked, display a symbol in the text pane. I am certain I have all the button properties set identical to each other. I want the button labels to display the same symbol that will be displayed in the text pane when pressed. In my initialization for the buttons, I set the labels to a single unicode representing the desired symbol, i.e., button.setText("\u00ac") for logical NOT. So when the button is pressed, I simply copy the button text to the text pane. The problem is, every one of the button unicodes display properly in the text pane, but only some of them display correctly on the buttons as labels. Stranger still is the fact that everything works properly on a mac but only displays this problem on a windows machine regardless which machine it was built on. I even tried using string builder and code point but with the same results.

    In the following code snippet, "argWindowDoc" is a StyledDocument belonging to the JTextPane

    Java Code:
            // Some of my button label inits
            propButton6.setText("\u2192");  // implies         this displays on the button
            propButton7.setText("\u00ac");  // logical NOT   this does not display on the button
            ... etc;
    
    
    
            // Here is the common listener for all the buttons. All button presses result in the proper
            // symbol being displayed on the text pane.
            private void propButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            try {
                // Get the particular button that triggered this event
                JButton jb = (JButton)evt.getSource();
    
                // Display the symbol in the argument window
                argWindowDoc.insertString(argWindowDoc.getLength(),
                                jb.getText(),
                                argWindowDoc.getStyle("regular"));
            } catch (Exception e){}
        }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Weird.
    I just tried it, with a basic button and that code, and I get the symbol.
    Windows 7.
    Might try later on on my old laptop, but this looks like something is missing from your character set on that machine?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    "\u00ac" as a JButton text displays for me using Windows LaF as well as the default Metal.
    Java Code:
    Microsoft Windows XP [Version 5.1.2600]
    
    java version "1.6.0_20"
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
    Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
    What does this return?
    Java Code:
    button.getFont().canDisplayUpTo("\u00ac")
    db

  4. #4
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    I'm sorry, I mislabeled the ones that don't display on the button. Here is a short list of unicodes that do display on the buttons and ones that do not. Note that all of them do display on both the JTextPane and JTextArea.

    Java Code:
            propButton1.setText("\u22a4");  // logical true                 does not display on the button
            propButton2.setText("\u22a5");  // logical false                does not display
            propButton3.setText("\u0028");  // left parenthesis           does display
            propButton4.setText("\u0029");  // right parenthesis         does display
            propButton5.setText("\u21d4");  // if and only if               does not display
            propButton6.setText("\u2192");  // implies                       does display

  5. #5
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    What does this return?
    Java Code:
    button.getFont().canDisplayUpTo("\u00ac")
    db[/QUOTE]

    Java Code:
    propButton1.getFont().canDisplayUpTo("\u00ac");    returns -1
    propButton1.getFont().canDisplayUpTo("\u22a4");    returns 0
    What's the solution to not getting the -1?

  6. #6
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    Problem solved! Thank you DarrylBurke for showing me canDisplayUpTo. I never noticed that. I was able to find a font that worked for all unicodes that I need to display. Thanks to all.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

Similar Threads

  1. Understanding Text pane use
    By sunde887 in forum New To Java
    Replies: 1
    Last Post: 03-25-2011, 09:38 AM
  2. Copying a text value from a textbox to a label
    By Weeman5872 in forum New To Java
    Replies: 3
    Last Post: 01-16-2011, 02:32 PM
  3. Replies: 1
    Last Post: 08-16-2010, 10:49 AM
  4. add tabbed pane to the frame on a button click
    By Mahaveer in forum New To Java
    Replies: 0
    Last Post: 11-20-2009, 09:19 AM
  5. Drag out text editor pane
    By p4ndaman in forum Eclipse
    Replies: 3
    Last Post: 07-21-2008, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •