Displaying Chinese and Japanese characters on Swing components.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaskarbasak
    New Member
    • Feb 2008
    • 27

    Displaying Chinese and Japanese characters on Swing components.

    Hi,

    I'm having problems displaying Chinese and Japanese characters on Swing components. I know some conversion should be done. Do you have some source code sample or any idea ?

    Thanks!
    vaskar
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by vaskarbasak
    Hi,

    I'm having problems displaying Chinese and Japanese characters on Swing components. I know some conversion should be done. Do you have some source code sample or any idea ?
    Most likely your selected font can't display the glyphs of any CJK character.
    Try to set the font to "Arial MS Unicode" if you're running on an MS Windows
    computer. There is no need to convert the String itself.

    kind regards,

    Jos

    Comment

    • vaskarbasak
      New Member
      • Feb 2008
      • 27

      #3
      It is not working...

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by vaskarbasak
        It is not working...
        Can you show us a bit of relevant code? Just a few lines please.

        "it is not working" is too vague to answer. Can you select the font I mentioned?
        Can you read your Chinese/Japanese data correctly?

        kind regards,

        Jos

        Comment

        • vaskarbasak
          New Member
          • Feb 2008
          • 27

          #5
          here i paste my code.


          public Component getTableCellRen dererComponent( JTable table, Object value,
          boolean isSelected, boolean hasFocus, int row, int column) {
          if (isSelected) {
          setForeground(t able.getSelecti onForeground()) ;
          setBackground(t able.getSelecti onBackground()) ;
          } else {
          setForeground(t able.getForegro und());
          setBackground(t able.getBackgro und());
          }
          // setFont(new Font("Arial", Font.BOLD, 12));
          //setFont(new Font("MS Gothic", Font.BOLD, 12));
          if (hasFocus) {
          setBorder(UIMan ager.getBorder( "Table.focusCel lHighlightBorde r"));
          if (table.isCellEd itable(row, column)) {
          setForeground(U IManager.getCol or("Table.focus CellForeground" ));
          setBackground(U IManager.getCol or("Table.focus CellBackground" ));
          }
          } else {
          setBorder(new EmptyBorder(1, 2, 1, 2));
          }
          setFont(new Font("Arial MS Unicode", Font.BOLD, 12));
          setText((value == null) ? "" : value.toString( ));
          return this;
          }


          Yes read Chinese/Japanese data correctly.

          Thanks!
          vaskar

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            We have to disect this nasty little problem step by step then; does your value.toString( )
            return the correct String? Does an Arial MS Unicode font exist on your computer?
            What is the range of characters it can render? (see the Font class API docs).

            kind regards,

            Jos

            Comment

            • vaskarbasak
              New Member
              • Feb 2008
              • 27

              #7
              Thanks! At last it is working....

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by vaskarbasak
                Thanks! At last it is working....
                You're welcome of course; what was the problem actually? Maybe other readers
                are interested in your problem and solution.

                kind regards,

                Jos

                Comment

                • Shilpa Indian
                  New Member
                  • Aug 2013
                  • 1

                  #9
                  I had the same problem. Using Font Helvetica in place of Arial solved the problem

                  Comment

                  Working...