Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Aqua-style Box in Swing



Julian, it turns out you can have a tab pane without any tabs, you just can't add() anything to it. With that in mind, the following trivial hack puts a Box around any JPanel, which looks just like a real Box in OS X. (I'd be keen to see how it renders on Windows.) Note that you can not, however, nest these fakey boxes to get that nice increasing darkness to their backgrounds seen when nesting real NSBoxes.






import javax.oy.JPanel; import javax.swing.JTabbedPane; import javax.swing.OverlayLayout; import javax.swing.BorderFactory; import java.awt.Insets;

/**
 * BoxPanel simulates the popular box-style container widget in OS X.
 *
 * This trivial code is public domain.
 *
 * @author Nicholas R. Rinard
 * @version 1.0
 */
public class BoxPanel extends JPanel {

    private final JTabbedPane underlayPanel = new JTabbedPane();
    private final JPanel overlayPanel;
    private final OverlayLayout layout;

/**
* This method prepares the parameter for overlay over a box-border panel
* by making it transparent and padding its borders.
*/
public BoxPanel( JPanel contents ) {
contents.setOpaque( false );
contents.setBorder( BorderFactory.createEmptyBorder( 25,15,15,15 ) );


        this.overlayPanel = contents;
        this.layout = new OverlayLayout( this );
        this.setLayout( this.layout );

        this.add( "box-panel-top-layer", overlayPanel );
        this.add( "box-panel-bottom-layer", underlayPanel );
    }
}

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Aqua-style Box in Swing (From: Julian Wood <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.