Anj78
asked on
Custom Look and Feel in java.
I am implementing Custom Look and feell for java application .And i want to change buttons should paint with red .i implement the following class.and i have My custom look and feel class where i put the default behaviour of button into table.and i have set the look and feel as custom look and feel.
but still i cant't see custom LAF in to button .
Do i amplement it right ?
public class DefaultButtonUI extends ButtonUI{
public DefaultButtonUI() {
// TODO Auto-generated constructor stub
super();
}
protected static DefaultButtonUI buttonUI;
public static ComponentUI createUI (JComponent c) {
if (buttonUI == null) {
buttonUI = new DefaultButtonUI();
}
return buttonUI;
}
public void paint(Graphics g, JComponent c)
{
// Invoke the original UI delegate
buttonUI.paint( g, c );
ComponentUI ui2 = UIManager.getUI( c );
// Now do the custom painting
Rectangle r = c.getBounds();
g.setColor( Color.red );
g.drawLine( 0, 0, r.width, r.height );
g.drawLine( 0, r.height, r.width, 0 );
}
public void update(Graphics g, JComponent c) {
paint(g, c);
}
}
custom Look and feel class contains:
protected void initClassDefaults(UIDefaul ts table) {
super.initClassDefaults(ta ble);
table.put ("ButtonUI", "defaultlaf.DefaultButtonU I");
}
but still i cant't see custom LAF in to button .
Do i amplement it right ?
public class DefaultButtonUI extends ButtonUI{
public DefaultButtonUI() {
// TODO Auto-generated constructor stub
super();
}
protected static DefaultButtonUI buttonUI;
public static ComponentUI createUI (JComponent c) {
if (buttonUI == null) {
buttonUI = new DefaultButtonUI();
}
return buttonUI;
}
public void paint(Graphics g, JComponent c)
{
// Invoke the original UI delegate
buttonUI.paint( g, c );
ComponentUI ui2 = UIManager.getUI( c );
// Now do the custom painting
Rectangle r = c.getBounds();
g.setColor( Color.red );
g.drawLine( 0, 0, r.width, r.height );
g.drawLine( 0, r.height, r.width, 0 );
}
public void update(Graphics g, JComponent c) {
paint(g, c);
}
}
custom Look and feel class contains:
protected void initClassDefaults(UIDefaul
super.initClassDefaults(ta
table.put ("ButtonUI", "defaultlaf.DefaultButtonU
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ksivananth,
I am looking for your solution.
Thanks.
I am looking for your solution.
Thanks.
ASKER
i got that i used wrong package.
Thanks.
Thanks.
ASKER
the DefaultButtonUI which i have implemented is write ?
I am new for this look and feel .Please guide me .....
Thanks.