Wednesday, 2 April 2014

How To set Liquid Look And Feel To java Swing Frame



import javax.swing.*;
import javax.swing.plaf.metal.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class LookAndFeel
{
    public static void main(String[] args)
    {
        try
        {
                    javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
            }
        catch (Exception e)
        {
                System.out.println("Error Loading Theme:" + e.toString());
                try
                {
                    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
                }
                catch (Exception err)
                {
                        System.out.println("Error loading myXPStyleTheme:" + err.toString());
                }
           }
        new Login();
    }
}
class Login extends JFrame
{
    JButton btnok,btnreset,btncancel;
    JLabel lblunm,lblpsw,lbltitle,lblwait;
    JTextField txtunm;
    JPasswordField txtpsw;
    public static JPanel JPContainer = new JPanel();
    JLabel JLPicture1 = new JLabel();
    Dimension screen =    Toolkit.getDefaultToolkit().getScreenSize();
   
    String StrBusinesTitle;
   
   
   
   
    public Login()
    {
        super("LoginForm");
       
        JPContainer.setLayout(null);
        lbltitle=new JLabel("Welcome TO Login Form");
        lbltitle.setBounds(60,10,250,30);
        lbltitle.setFont(new Font("Dialog", Font.ITALIC, 20));
        lbltitle.setForeground(Color.BLUE);
        JPContainer.add(lbltitle);
       
       
       
        lblunm=new JLabel("UserName  : ");
        lblunm.setBounds(30,70,90,20);
        lblunm.setFont(new Font("Dialog", Font.PLAIN,15));
        JPContainer.add(lblunm);
       
        lblpsw=new JLabel("Password   : ");
        lblpsw.setBounds(30,110,90,20);
        lblpsw.setFont(new Font("Dialog", Font.PLAIN,15));
        JPContainer.add(lblpsw);
       
        txtunm=new JTextField();
        txtunm.setBounds(125,70,160,20);
        txtunm.setFont(new Font("Dialog", Font.PLAIN,15));
        JPContainer.add(txtunm);
       
       
        txtpsw=new JPasswordField();
        txtpsw.setBackground(Color.WHITE);
        txtpsw.setBounds(125,110,160,20);
        txtpsw.setFont(new Font("Dialog", Font.PLAIN,13));
        JPContainer.add(txtpsw);
       
        btnok=new JButton("Login");
        btnok.setBounds(5,170,100,30);
        btnok.setFont(new Font("Dialog", Font.PLAIN,13));
        //btnok.addActionListener(this);
        JPContainer.add(btnok);
       
        btnreset=new JButton("Reset");
        btnreset.setBounds(115,170,100,30);
        btnreset.setFont(new Font("Dialog", Font.PLAIN,13));
        //btnreset.addActionListener(this);
        JPContainer.add(btnreset);
       
        btncancel=new JButton("Cancel",new ImageIcon("images/cancel.png"));
        btncancel.setBounds(220,170,110,30);
        btncancel.setFont(new Font("Dialog", Font.PLAIN,13));
        //btncancel.addActionListener(this);
        JPContainer.add(btncancel);
       
        lblwait=new JLabel("Wait While Database Is Loading......");
        lblwait.setBounds(10,210,220,20);
        lblwait.setFont(new Font("Dialog", Font.PLAIN,13));
        lblwait.setVisible(false);
        //lblwait.setEnabled(false);
        JPContainer.add(lblwait);
       
        //lbltitle.setFont(new Font());
        getContentPane().add(JPContainer);
        setSize(350,300);
        setLocation((screen.width - 400)/2,((screen.height-300)/2)-45);
        setVisible(true);
    }
}

First to set this look you need have one package ,
Download Form here

https://docs.google.com/file/d/0B-9VffJqfTIwbHg3TjRlNzNPcms/edit?pli=1

Extract folder to any drive and just run LookAndFeel.java file from command prompt


No comments:

Post a Comment