net.xoetrope.swing.util
Class XComponentUiHelper

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by net.xoetrope.swing.util.XComponentUiHelper

public class XComponentUiHelper
extends javax.swing.plaf.ComponentUI

A helper to set a ComponentUI painter. The painter must extend the UI appropriate delegate for the component.


 public class XButtonUI extends ButtonUI
 {
   ButtonUI ui;
   
   public void setup( JButton c )
   {
     ui = (ButtonUI)XComponentUiHelper.setUI( (JComponent)c, this );
   }
     
   // Paints an X over the button.
   public void paint(Graphics g, JComponent c) 
   {
     // Invoke the original UI delegate
     ui.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 );
   }  
 }
 


 Then, to install the painter delegate:

    new XButtonUI().setup( submitBtn );
 

Copyright (c) Xoetrope Ltd., 2002-2006, This software is licensed under the Xoetrope Public License (XPL), please see license.txt for more details


Constructor Summary
XComponentUiHelper()
           
 
Method Summary
static javax.swing.plaf.ComponentUI setUI(javax.swing.JComponent comp, javax.swing.plaf.ComponentUI painterUI)
          Creates a new instance of XComponentUiHelper
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XComponentUiHelper

public XComponentUiHelper()
Method Detail

setUI

public static javax.swing.plaf.ComponentUI setUI(javax.swing.JComponent comp,
                                                 javax.swing.plaf.ComponentUI painterUI)
Creates a new instance of XComponentUiHelper

Parameters:
comp - the component being painted
painterUI - the new ComponentUI instance