SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Show text in Jtextarea,UTF-8

    Code:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    
    public class Main {
    public static void main(String args[])throws IOException
    {
    // instantiate data input stream
    DataInputStream din = new DataInputStream (System.in);
    // Ask user to enter a message
    System.out.println("please enter a message:");
    // read message from keyboard
    FileInputStream in = null;
    InputStreamReader inchar=null;
    BufferedReader bufferchar=null;
    
    inchar = new InputStreamReader(System.in,"UTF8");
    bufferchar= new BufferedReader(inchar);
    String msg = bufferchar.readLine();
    // print message to screen
    System.out.println("you have entered: " + msg);
    JFrame frame = new JFrame("Reader test");
    JTextArea jta = new JTextArea(msg);
     jta.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(450,200);
    jta.setFont(Font.decode("Cp1256"));
    frame.add(jta);
    frame.setVisible(true);
    System.out.println(System.getProperty("file.encoding"));
    
    }
    }
    This is output:

    please enter a message:
    من

    you have entered: ??
    Cp1256
    and what I see in Jtextarea is

    ��
    How to solve it?
    I shall build a boat,I shall cast it in the water,
    I shall sail away from this strange earth,
    Where no one awaken the heroes in the wood of love

  2. #2
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have that specific font installed on your machine?
    baby steps... baby steps...

  3. #3
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    public class Main {
    public static void main(String args[])throws IOException
    {
    // instantiate data input stream
    DataInputStream din = new DataInputStream (System.in);
    // Ask user to enter a message
    System.out.println("please enter a message:");
    // read message from keyboard
    FileInputStream in = null;
    InputStreamReader inchar=null;
    BufferedReader bufferchar=null;

    inchar = new InputStreamReader(System.in,"UTF8");
    bufferchar= new BufferedReader(inchar);
    String msg = bufferchar.readLine();
    // print message to screen
    System.out.println("you have entered: " + msg);
    JFrame frame = new JFrame("Reader test");
    JTextArea jta = new JTextArea(msg);
    jta.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    jta.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(450,200);
    //jta.setFont(Font.decode("Cp1256"));

    frame.add(jta);
    frame.setVisible(true);
    System.out.println(System.getProperty("file.encoding"));

    }
    }
    Now it prints in window
    �� ����

    I think It is not about the font
    I shall build a boat,I shall cast it in the water,
    I shall sail away from this strange earth,
    Where no one awaken the heroes in the wood of love

  4. #4
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    
    public class Main {
    public static void main(String args[])throws IOException
    {
    // instantiate data input stream
    DataInputStream din = new DataInputStream (System.in);
    // Ask user to enter a message
    System.out.println("please enter a message:");
    // read message from keyboard
    FileInputStream in = null;
    InputStreamReader inchar=null;
    BufferedReader bufferchar=null;
    
    inchar = new InputStreamReader(System.in,"windows-1256");
    bufferchar= new BufferedReader(inchar);
    String msg = bufferchar.readLine();
    // print message to screen
    System.out.println("you have entered: " + msg);
    JFrame frame = new JFrame("Reader test");
    JTextArea jta = new JTextArea(msg);
    jta.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    jta.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(450,200);
    //jta.setFont(Font.decode("Cp1256"));
    jta.setFont(Font.decode("IranNastaliq-24"));
    frame.add(jta);
    frame.setVisible(true);
    System.out.println(System.getProperty("file.encoding"));
    
    }
    }
    It works, But I want to know is it possible that put this text in window so it has distance to right side?
    I shall build a boat,I shall cast it in the water,
    I shall sail away from this strange earth,
    Where no one awaken the heroes in the wood of love

  5. #5
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May anyone answer my question?

    I have another question: How is it possible to create color, size for three line in a Jtextarea so every line has its own color and font?
    I shall build a boat,I shall cast it in the water,
    I shall sail away from this strange earth,
    Where no one awaken the heroes in the wood of love


Bookmarks

Posting Permissions

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