I'd like to add some small functionality do default
TabbedPaneUI component. It is now like this:
public class HBasicTabbedPaneUI extends BasicTabbedPaneUI {
public static ComponentUI createUI(JComponent c) {
return new HBasicTabbedPaneUI();
}
@Override
public void installUI(JComponent c) {
super.installUI(c);
// Everything is like in parent, but we add a listener.
c.addContainerListener(new ContainerListener() {
public void componentAdded(ContainerEvent e) {
System.err.println("Comp added: "+e.getChild().getClass());
}
public void componentRemoved(ContainerEvent e) {
System.err.println("Comp rmvd: "+e.getChild().getClass());
}
});
}
}
I install this using UIManager and it works ok, until i use some
extended L&F.
It always reverts my tabbed panes to the basicui behavior ... So when I
use some L&F (like JGoodies) it is a step backward, because
tab panes do not look like originally in jgoodies.
I'd prefer to make an UI component, that does not extend the basic ui,
but can decorate any other implementation of TabbedPaneUI installed
previously by L&F. Is it possible, at least to decorate ui components
from jgoodies ? I need only to add a small listener.
Kleopatra - 16 Feb 2006 11:45 GMT
> I'd like to add some small functionality do default
> TabbedPaneUI component.
[..]
> I'd prefer to make an UI component, that does not extend the basic ui,
> but can decorate any other implementation of TabbedPaneUI installed
> previously by L&F. Is it possible, at least to decorate ui components
> from jgoodies ? I need only to add a small listener.
The way to go is to implement a "incomplete" LookAndFeel (handling only
the components you want to decorate) and register it with the UIManager via
UIManager.addAuxiliaryLookAndFeel(myDecoratingLF);
rough code sketch:
[code]
public MyDecoratingLF extends LookAndFeel {
//...
public UIDefaults getDefaults() {
if (myDefaults == null) {
initDefaults();
}
return myDefaults;
}
private void initDefaults() {
myDefaults = new MyUIDefaults();
Object[] mydefaults = { "TabbedPaneUI",
"snippets.focus.tabbedpane.CrossLFTabbedPaneUI",
};
myDefaults.putDefaults(mydefaults);
}
/**
* UIDefaults without error msg.
*
*/
private static class MyUIDefaults extends UIDefaults {
protected void getUIError(String msg) {
// overridden to do nothing - the LF is incomplete as of
component types
}
}
}
public class CrossLFTabbedPaneUI extends TabbedPaneUI {
private ContainerListener listener;
public static ComponentUI createUI(JComponent c) {
return new CrossLFTabbedPaneUI();
}
public void installUI(JComponent comp) {
comp.addContainerListener(getContainerListener());
}
public void uninstallUI(JComponent comp) {
comp.removeContainerListener(getContainerListener());
}
// implement the abstract TabbedPaneUI methods to do nothing
// ...
}
There's a catch, though: some UIDelegates don't play well with the
MultiXXUI delegates because they expect a BasicXXUI - for more details, see
http://forums.java.net/jive/thread.jspa?forumID=73&threadID=7713
and the resulting #6307075 in Sun's BugParade. Feel free to vote for the
bug - maybe we can build pressure to tackle it soon :-)
Cheers
Jeanette