• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1087
  • Last Modified:

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
  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) {
    table.put ("ButtonUI", "defaultlaf.DefaultButtonUI");
  • 3
1 Solution
try this,

        Object[] defaults = { "ButtonUI", "defaultlaf.DefaultButtonUI" } ;

        table.putDefaults( defaults );
Anj78Author Commented:
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 .....
Anj78Author Commented:
Hi Ksivananth,
I am looking for your solution.
Anj78Author Commented:
i got that i used wrong package.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now