org.formaria.swing.util
Class ComponentUiHelper

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by org.formaria.swing.util.ComponentUiHelper

public class ComponentUiHelper
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 ButtonUI extends ButtonUI
 {
   ButtonUI ui;
   
   public void setup( JButton c )
   {
     ui = (ButtonUI)ComponentUiHelper.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 ButtonUI().setup( submitBtn );
 

Copyright (c) Formaria Ltd., 2008, This software is licensed under the Formaria Public License (XPL), please see license.txt for more details


Constructor Summary
ComponentUiHelper()
           
 
Method Summary
static javax.swing.plaf.ComponentUI setUI(javax.swing.JComponent comp, javax.swing.plaf.ComponentUI painterUI)
          Creates a new instance of ComponentUiHelper
 
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

ComponentUiHelper

public ComponentUiHelper()
Method Detail

setUI

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

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