How to set JTable Titile with Sinhala Unicode value

This is regarding request of chathura and today i am going to add Unicode based title to JTable. First create a new project using NetBeans and add a new form to project. Then add a new table to JFrame and edit the default table headers with Unicode values.

RC on JTable -> Properties -> Go to Model -> and add your new table headers to there.

Add a new Class called MyFont and i use that class to set fonts to my application

Go to your Main method and add this code inside main method.

MyFont.setUIFont(new javax.swing.plaf.FontUIResource("Iskoola pota",Font.PLAIN,18));

Compile and Run your project and see the output.

To Download the full NetBeans Project click on the below button

Download

How to add uniocde to JOptionPane.showInputDialog in java – Uniocde example

This slideshow requires JavaScript.

In this example i will show create Unicode based Input dialog to your application.In here you can see lot of information’s about Unicode based java applications.First of all i had to define Unicode font for my input dialog.Because when i type Sinhala text in my text box which i used to get name from user it showed me only boxes.But after i set default font my application it has solved.See the code

Read More »

How to insert Unicode values to MySQL using Java-Part 3

This is the last part of our Unicode based project and in this project we will see how to retrieve our inserted values from MySQL table to our GUI.

You can see  i have a button and  one combo box retrieve data and display it.Once i click my button it will go to database and get values to array list and fill my combo box. See the below code i did that.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        ArrayList names = new ArrayList();

        try
        {
            conn=getcon.creatConnection();//getting connection

            //execute query

             ResultSet rs = conn.createStatement().executeQuery("select name from unicode");

             while (rs.next())
             {

                 String Cusname = rs.getString("name");
                 names.add(Cusname);

            }

             rs.close();
             DefaultComboBoxModel model = new DefaultComboBoxModel(names.toArray());
             cmboUnicode.setModel(model);

        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(rootPane, ex);
        }

    }

same as my previous post i have to create the object top of my class like this.

connection getcon = new connection();
Connection conn;

This method will called once i click the find button.These things normal than any other program.But you must concert clearly about my connection class. Here important things of the program are

Connection class , Use general Unicode font, Use java latest version, Handle exception while you are testing or develop it

Below you can download my complete project and if you have any problem comment on me.Thank you and best of luck

Download this video
Download Project

How to insert Unicode values to MySQL using Java-Part 2

This is the second part of my How to insert Unicode values to MySQL using Java tutorial and in this tutorial you will see how to insert Unicode format value to your MySQL table.Now we already have created a database,table and also nice GUI to communicate with our back end database. You can see below picture and that is the UI i use to insert and retrieve values from the MySQL table

In my GUI i have two text-boxes to insert values. I have assigned a variable to each and those are txtname and txtjob. See the below code how did i used to get values from text boxes and inserted into my table.

 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
//connection getcon = new connection();
//Connection conn; 

// you can also create object like above my code.But you have to crate again and again if you have several functions in your program.
        try{

         getcon.creatConnection().createStatement().executeUpdate("insert into unicode(name,job) values ('" + txtname.getText() + "','"+ txtjob.getText()+"')");

          JOptionPane.showMessageDialog(null, "Done") ;

         txtname.setText(null);
         txtjob.setText(null);

         txtname.requestFocus();
      }
      catch(Exception ex){

         JOptionPane.showMessageDialog(null,"Cannot insert data."+ ex.getMessage(), "Contact Editor",JOptionPane.ERROR_MESSAGE, null);//exeption hanling

      }

        // TODO add your handling code here:
    }

In my class i have created a new object top of my class and based on that i can access my connection class.

connection getcon = new connection();
Connection conn;

you can also create object like above my code.But you have to crate again and again if you have several functions in your program.After you download your complete project at the end of this tutorial you can see clearly and understand the full code.I used

JOptionPane.showMessageDialog

to display my successful message to user.

In next tutorials we will see how to retrieve data and display to simple combo box.

how to add sinhala to java GUI

Hi.. i think every programmer must aware about there own Unicode formats and how to add Unicode to their own program.I am going to say you how to enable java GUI with Sinhala Unicode values.

I am using Netbeans IDE and Java Development Kit 1.7 for develop Java programs.

Create a new form using Netbeans and add a Button from Swing containers. Then go to font item change it in to Iskoola pota. I used that Unicode font in my Program. See the image below

Then add a text to button as Unicode ( Sinahala ) format. You just copy the words from else where and paste it it text field. You will see something like \u0d86\u0dba values such as above my picture. Don’t worry in run time it will look like  as below picture.

Now you must be happy.

To view in Sinhala you must install the Sinhala Unicode for your computer. Other wise you will see some boxes in your button.

OK now you have done a Unicode based Java application using Java.

How to change Tooltips font in java / customize java Tooltips

Welcome again. Now i have different code for customize the  Tool tips in java programs. You can see i changed default tool tip font in to my own native language. It shows based on my Unicode language. I will show you how change this is.

String html =
            "<html><p><font color=\"#000\" " +
            "size=\"5\" face=\"Iskoola pota\">ආයුබෝවන් මෙම පනිවිඩය ඔබට සින්හලෙන් දිස්වන්නේ<br /> මෙම ජාවා වැඩසටහන සින්හල වැඩසටහනක්<br /> ලෙස සකසා ඇති නිසාය.." +
            "</font></p></html>";

        jButton1.setToolTipText(html);

See i told you this is easy. OK i have set tool tips for my jButton1 using my native language. You want to call this inside your constructors. I think you got it know. If not see code

public class joption extends javax.swing.JFrame {

    /** Creates new form joption */
    public joption() {
        initComponents();
        String html =
            "<html><p><font color=\"#000\" " +
            "size=\"5\" face=\"Iskoola pota\">ආයුබෝවන් මෙම පනිවිඩය ඔබට සින්හලෙන් දිස්වන්නේ<br /> මෙම ජාවා වැඩසටහන සින්හල වැඩසටහනක්<br /> ලෙස සකසා ඇති නිසාය.." +
            "</font></p></html>";

        jButton1.setToolTipText(html);

    }

I am using Netbeans as my IDE for develop java. If you have any problem please comment on this. Hope this was helpful to you friends.

how to set unicode(sinhala) font to JoptionPane in java / customize JoptionPane

Hi all now i am going to say you how to customize the JoptionPane in java. In here i  added Unicode type font to my message. Now we will see how to do it. Below you can see how you can customize your code for Unicode font..

String html =
            "<html><p><font color=\"#000\" " +
            "size=\"5\" face=\"Iskoola pota\">ආයුබෝවන් මෙම පනිවිඩය ඔබට සින්හලෙන් දිස්වන්නේ<br /> මෙම ජාවා වැඩසටහන සින්හල වැඩසටහනක්<br /> ලෙස සකසා ඇති නිසාය.." +
            "</font></p></html>";

        JOptionPane.showMessageDialog(null, html,"තොරතුරු පනිවිඩය",JOptionPane.INFORMATION_MESSAGE);

How nice it has changed know.. OK friends we will see in next post..