2 Replies Latest reply: May 30, 2009 10:17 AM by 807581 RSS

    JTextField and Farsi or Arabic fonts.

    807581
      Hi,
      My program is using MS Access and is working fine with all English fonts. But, when I use Farsi fonts, it displays ???? or boxes. Please, help; many thanks in advance. Here is what I tried but did not work!

      fnametxt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
      Font font1 = new Font("B Homa", Font.PLAIN, 12);
      fnametxt.setFont(font1);
      fnametxt.setBackground(Color.ORANGE);
        • 1. Re: JTextField and Farsi or Arabic fonts.
          807581
          I don't sure but perhaps the problem is that the font isn't present on the system or B Homa isn't correct.
          • 2. Re: JTextField and Farsi or Arabic fonts.
            807581
            Hope this might work

            step# 1: just ensure that the farsi fonts are installed, if not then download and install it (or just copy & paste the font files to system/fonts folder), ( I used AlKatib1, or Bitstream CyberBit fonts for Urdu input). you must also ensure that your system is also set for Farsi Locale ( i am sure it would be)

            Step# 2: After you have initialised the textfield,


            Adapt accordingly from the below peice of code,



            yourClassconstructor() {

            // instead of BitStream.. use font which ever is intalled
            yourFarsiTextFeild.setFont(new java.awt.Font("Bitstream Cyberbit" , 0, 14));

            yourFarsiTextFeild.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
            yourFarsiFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {

            yourFarsiFocusLost(evt);
            }
            });

            }

            // Handler Functions

            private void yourFarsiFocusGained(java.awt.event.FocusEvent evt) {
            // TODO add your handling code here:
            yourFarsiTextFeild.getInputContext().selectInputMethod(new Locale("fa", "IR"));

            }

            private void yourFarsiFocusLost(java.awt.event.FocusEvent evt) {
            // TODO add your handling code here:
            yourFarsiTextFeild.getInputContext().selectInputMethod(new Locale("en", "US"));
            }

            you will find Locale class in java.util. package. So dont forget to import it.



            Step #3 See If it works, ( I know for sure that it did work on MySql Database), and if you in case consider
            the MySql database, then dont forget to add COLLATE attribute to the requisite field. e.g

            Farsi_Name` VARCHAR(75) CHARACTER SET 'cp1256' COLLATE 'cp1256_general_ci' NULL DEFAULT NULL ,