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
{
MyDesign()
{
super("Look and Feel by Prashant Chandrakar");
try
{
////import xml file
String xmlFile = "myproperty.xml";
SynthLookAndFeel lookandfeel = new SynthLookAndFeel();
lookandfeel.load(MyDesign.class.getResourceAsStream(xmlFile), MyDesign.class);
////set look and feel
UIManager.setLookAndFeel(lookandfeel);
this.getContentPane().setBackground(Color.DARK_GRAY );
this.getContentPane().setLayout(new FlowLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
////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
contentPane.setLayout(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)
{
System.out.println(e);
}
this.setSize(350,200);
this.setVisible(true);
}
private void addComponent(Container container, Component c, int x, int y, int width, int height)
{
c.setBounds(x, y, width, height);
this.add(c);
}
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
ScreenShot:-
This comment has been removed by the author.
ReplyDelete