Link to home
Start Free TrialLog in
Avatar of Anj78
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(UIDefaults table) {
    super.initClassDefaults(table);
    table.put ("ButtonUI", "defaultlaf.DefaultButtonUI");
  }
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anj78
Anj78

ASKER

I tried above code but there is no effect on button.
the DefaultButtonUI which i have implemented is write ?
I am new for this look and feel .Please guide me .....
Thanks.
Avatar of Anj78

ASKER

Hi Ksivananth,
I am looking for your solution.
Thanks.
Avatar of Anj78

ASKER

i got that i used wrong package.
Thanks.