Custom Look and Feel in java.

Posted on 2007-10-04
Last Modified: 2013-11-23
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( );
  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");
Question by:Anj78
    LVL 26

    Accepted Solution

    try this,

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

            table.putDefaults( defaults );

    Author Comment

    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 .....

    Author Comment

    Hi Ksivananth,
    I am looking for your solution.

    Author Comment

    i got that i used wrong package.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    canBalance challenge 34 55
    scoresIncreasing challenge 10 47
    wordappend challenge 8 45
    groovy example issue 10 32
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now