001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: JBorderlessButton.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.swing;
009:
010: import javax.swing.Action;
011: import javax.swing.Icon;
012: import javax.swing.JButton;
013:
014: /**
015: * A JButton that maintains its borderless look when the look
016: * & feel changes.
017: *
018: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
019: * @version $Revision: 3634 $
020: * @see JButton
021: * @since 1.0
022: */
023: public class JBorderlessButton extends JButton {
024: private static final long serialVersionUID = 6092380900896756322L;
025:
026: /**
027: * Creates a button with no set text or icon.
028: * @since 1.0
029: */
030: public JBorderlessButton() {
031: super ();
032: setStyle();
033: }
034:
035: /**
036: * Creates a button with an icon.
037: *
038: * @param icon the Icon image to display on the button
039: * @since 1.0
040: */
041: public JBorderlessButton(Icon icon) {
042: super (icon);
043: setStyle();
044: }
045:
046: /**
047: * Creates a button with text.
048: *
049: * @param text the text of the button
050: * @since 1.0
051: */
052: public JBorderlessButton(String text) {
053: super (text);
054: setStyle();
055: }
056:
057: /**
058: * Creates a button where properties are taken from the
059: * Action supplied.
060: *
061: * @param a
062: * @since 1.0
063: */
064: public JBorderlessButton(Action a) {
065: super (a);
066: setStyle();
067: }
068:
069: /**
070: * Creates a button with initial text and an icon.
071: *
072: * @param text the text of the button.
073: * @param icon the Icon image to display on the button
074: * @since 1.0
075: */
076: public JBorderlessButton(String text, Icon icon) {
077: super (text, icon);
078: setStyle();
079: }
080:
081: /**
082: * Notification from the UIFactory that the L&F
083: * has changed. Maintains the borderless look.
084: *
085: * @see JButton#updateUI()
086: * @since 1.0
087: */
088: public void updateUI() {
089: super .updateUI();
090: setStyle();
091: }
092:
093: /**
094: * Makes this button borderless.
095: * @since 1.0
096: */
097: private void setStyle() {
098: setBorder(null);
099: }
100: }
|