Friday, February 20, 2009

Custom look and feel in JAVA via XML file

Hi Everyone,

If you want to make your own images on button,
Or want to change button style in over event or clicked event.

If you want to rounded corner text box or whatever you want.
Just see the below code.
Here i have three images.The first two are for buttons and last one for text box.
Just save these images on images folder and change their path in xml file.
After my java code i am also posting xml file code.
just save code in "myproperty.xml" file and put aside of java file.

for full source code follow the link

* look and feel from your own images
* Supply images via xml file
* apply images on textbox button etc
* Copyright 2009@ yuvadeveloper
* Code by:- Prashant Chandrakar
* */
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.synth.*;
public class MyDesign extends JFrame
super("Look and Feel by Prashant Chandrakar");
////import xml file
String xmlFile = "myproperty.xml";
SynthLookAndFeel lookandfeel = new SynthLookAndFeel();
lookandfeel.load(MyDesign.class.getResourceAsStream(xmlFile), MyDesign.class);
////set look and feel
this.getContentPane().setBackground(Color.DARK_GRAY );
this.getContentPane().setLayout(new FlowLayout());
////Adding labels TextField
JLabel uname = new JLabel("UserName");
JLabel pword = new JLabel("Password");
JTextField utxt = new JTextField(20);
JTextField ptxt = new JTextField(20);
Container contentPane = this.getContentPane();
////setting layout to null
addComponent(contentPane, uname, 40, 27, 100, 25);
addComponent(contentPane, utxt, 150, 27, 100, 25);
addComponent(contentPane, pword, 40, 70, 100, 25);
addComponent(contentPane, ptxt, 150, 70, 100, 25);
JButton btsave = new JButton("SAVE");
addComponent(contentPane, btsave, 100, 107, 104, 33);
catch (Exception e)
private void addComponent(Container container, Component c, int x, int y, int width, int height)
c.setBounds(x, y, width, height);
public static void main(String[] args) throws Throwable
new MyDesign();

XML File
Save file as "myproperty.xml" put together with java file"

Related Images:- Just save as it is and put inside images folder


1 comment: