?
Solved

Custom Look and Feel in java.

Posted on 2007-10-04
4
Medium Priority
?
1,063 Views
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
    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");
  }
0
Comment
Question by:Anj78
  • 3
4 Comments
 
LVL 26

Accepted Solution

by:
ksivananth earned 1500 total points
ID: 20013612
try this,

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

        table.putDefaults( defaults );
0
 

Author Comment

by:Anj78
ID: 20013738
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.
0
 

Author Comment

by:Anj78
ID: 20014218
Hi Ksivananth,
I am looking for your solution.
Thanks.
0
 

Author Comment

by:Anj78
ID: 20014514
i got that i used wrong package.
Thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

839 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