I have an application with a default Look and Feel (insubstantial
) and many defaults setted, such like:
UIManager.put( "List.foreground", Color.BLACK );
UIManager.put( xyz, zyzLEF );
//around 150 istructions like that
This application it's huge and there are many overrides tailered on client's needs, however now I have the need to create my own JButton
with some settings (Foreground
, Background
, Font
and so on) that does not act as I want due to the defaults (as example, setOpaque(true||false)
has no effects at all).
So I'm trying to create my own JButton
ignoring default look and feel, something like:
public class MyButton extends JButton {
public MyButton(String text, int lineHeight)
{
super(text);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setBackground(Color.WHITE);
//foo
setOpaque(true);
}
@Override
public String getUIClassID() {
return "MyButton";
}
and on startup:
UIManager.put("MyButton","javax.swing.plaf.ButtonUI");
this cause this error:
UIDefaults.getUI() failed: createUI() failed for com.foo.MyButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=null,paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Hello World,defaultCapable=true] java.lang.reflect.InvocationTargetException
java.lang.Error
at javax.swing.UIDefaults.getUIError(UIDefaults.java:732)
at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:130)
I bet delegation to UIManger is wrong, but I can't get how to ignore current defaults for a custom item. Any idea?
Thanx in advice