Java Code Examples for javax.swing.AbstractButton#setIcon()

The following examples show how to use javax.swing.AbstractButton#setIcon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractToolbarFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void configureToolbarButton (AbstractButton item, String containerCtx, String action, ActionProvider provider, Map ctx) {
        item.setFocusable(false);
        item.setName(action);
        item.putClientProperty (KEY_ACTION, action);
        item.setToolTipText(
            provider.getDisplayName(action, containerCtx));
//        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = ctx == null ? ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, ctx);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0;
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
        item.setVisible (visible);
        boolean toggled = (state & ActionProvider.STATE_SELECTED) != 0;
        item.setSelected(toggled);
//        item.setMnemonic(provider.getMnemonic(action, containerCtx));
//        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
Example 2
Source File: ButtonHelper.java    From javamoney-examples with Apache License 2.0 6 votes vote down vote up
/**
 * This method builds the specified button according to the specified
 * parameters.
 *
 * @param button The button to build.
 * @param text The text displayed on the button.
 * @param icon The icon to use.
 * @param handler The action listener that monitors the buttons events.
 * @param command The action command used when the button is clicked.
 * @param group The group the button should belong to.
 * @param selected The initial selected state of the button.
 * @param tip The tool tip to display.
 */
public
static
void
buildButton(AbstractButton button, String text, Icon icon,
    ActionListener handler, String command, ButtonGroup group,
    boolean selected, String tip)
{
  button.addActionListener(handler);
  button.setActionCommand(command);
  button.setIcon(icon);
  button.setSelected(selected);
  button.setText(text);
  button.setToolTipText(tip);

  if(group != null)
  {
    group.add(button);
  }
}
 
Example 3
Source File: IconLoader.java    From swift-k with Apache License 2.0 6 votes vote down vote up
public static void setIcon(AbstractButton button, String res, String alt) {
    try {
        URL url = GraphsPanel.class.getClassLoader().getResource(res);
        if (url == null) {
            button.setText(alt);
        }
        else {
            BufferedImage icon = ImageIO.read(url);
            button.setIcon(new ImageIcon(icon));
        }
    }
    catch (Exception e) {
        button.setText(alt);
    }
    button.setToolTipText(alt);
}
 
Example 4
Source File: CampaignEditor.java    From open-ig with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create a imaged button for the given menu item.
 * @param graphicsResource the graphics resource location.
 * @param tooltip the tooltip text
 * @param inMenu the menu item to relay the click to.
 * @param toggle create a toggle button?
 * @return the button
 */
AbstractButton createFor(String graphicsResource, String tooltip, final JMenuItem inMenu, boolean toggle) {
	AbstractButton result = toggle ? new JToggleButton() : new JButton();
	URL res = CampaignEditor.class.getResource("/hu/openig/editors/" + graphicsResource);
	if (res != null) {
		ImageIcon icon = new ImageIcon(res);
		result.setIcon(icon);
		inMenu.setIcon(icon);
	}
	result.setToolTipText(tooltip);
	result.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			inMenu.doClick();
		}
	});
	return result;
}
 
Example 5
Source File: ToolButtonFactory.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static void configure(AbstractButton button) {

        RolloverButtonEventListener l = new RolloverButtonEventListener();
        button.addMouseListener(l);
        button.addItemListener(l);

        if (button.getAction() != null) {
            if (button.getIcon() != null) {
                button.putClientProperty("hideActionText", Boolean.TRUE);
            }
            Object largeIcon = button.getAction().getValue("_largeIcon");
            if (largeIcon instanceof Icon) {
                button.setIcon((Icon) largeIcon);
            }
        }

        Icon icon = button.getIcon();
        int minWidth = BUTTON_MIN_SIZE;
        int minHeight = BUTTON_MIN_SIZE;
        if (icon != null) {
            button.setText(null);
            minWidth = Math.max(icon.getIconWidth(), BUTTON_MIN_SIZE);
            minHeight = Math.max(icon.getIconHeight(), BUTTON_MIN_SIZE);
            if (icon instanceof ImageIcon) {
                button.setRolloverIcon(createRolloverIcon((ImageIcon) icon));
            }
        } else {
            button.setText("[?]");
        }
        final int space = 3;
        Dimension prefSize = new Dimension(minWidth + space, minHeight + space);
        Dimension minSize = new Dimension(minWidth, minHeight);
        Dimension maxSize = new Dimension(minWidth + space, minHeight + space);
        button.setPreferredSize(prefSize);
        button.setMaximumSize(maxSize);
        button.setMinimumSize(minSize);

    }
 
Example 6
Source File: SpectrumChooser.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    final Object source = e.getSource();
    if (source instanceof AbstractButton) {
        AbstractButton collapseButton = (AbstractButton) source;
        toggleCollapsed(index);
        if (collapsed[index]) {
            collapseButton.setIcon(icons[0]);
            collapseButton.setRolloverIcon(roll_over_icons[0]);
        } else {
            collapseButton.setIcon(icons[1]);
            collapseButton.setRolloverIcon(roll_over_icons[1]);
        }
    }
}
 
Example 7
Source File: BETitlePane.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
 * 为按钮设置图标,并据原图icon自动调用方法 {@link #filterWithRescaleOp(ImageIcon, float, float, float, float)}
 * 使用滤镜分别生成RolloverIcon、PressedIcon并设置之.
 * 
 * @param btn
 * @param ico
 * @since 3.5
 * @deprecated since 3.6
 */
public static void setButtonIcon(AbstractButton btn, Icon ico)
{
	//* 图片设定
	btn.setIcon(ico);
	if(ico != null && ico instanceof ImageIcon)
	{
		//rover时图片颜色变成红色
		btn.setRolloverIcon(BEUtils.filterWithRescaleOp((ImageIcon)ico, 2f, 1f, 1f, 1f));
		//press时图片颜色变成淡红色
		btn.setPressedIcon(BEUtils.filterWithRescaleOp((ImageIcon)ico, 2f, 1f, 1f, 0.5f));
	}
}
 
Example 8
Source File: TGToolBar.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
private AbstractButton getImageButton( AbstractButton button, String iconPrefix, String iconSuffix ){
	button.setHorizontalTextPosition(JButton.CENTER);
	button.setVerticalTextPosition(JButton.CENTER);
	button.setBorderPainted( false );
	button.setContentAreaFilled( false );
	button.setFocusPainted( false );
	button.setMargin( new Insets(0,0,0,0) );
	button.setIcon( TGResourceUtils.loadIcon( iconPrefix + iconSuffix ) );
	button.setPressedIcon( TGResourceUtils.loadIcon( iconPrefix + "_pressed" + iconSuffix ) );
	button.setRolloverIcon( TGResourceUtils.loadIcon( iconPrefix + "_over" + iconSuffix ) );
	button.setSelectedIcon( TGResourceUtils.loadIcon( iconPrefix + "_selected" + iconSuffix ) );
	button.setRolloverSelectedIcon( TGResourceUtils.loadIcon( iconPrefix + "_selected_over" + iconSuffix ) );
	return button;
}
 
Example 9
Source File: LargeNavigationPanelUI.java    From pumpernickel with MIT License 5 votes vote down vote up
protected AbstractButton createLastButton() {
	AbstractButton button = new JButton();
	format(button);
	button.setIcon(new LastIcon(2, 24, 24, Color.lightGray));
	button.setRolloverIcon(new LastIcon(2, 24, 24, Color.white));
	button.setDisabledIcon(new LastIcon(2, 24, 24, Color.darkGray));
	button.setName("Spinner.lastButton");
	installLastButtonListeners(button);
	return button;
}
 
Example 10
Source File: LargeNavigationPanelUI.java    From pumpernickel with MIT License 5 votes vote down vote up
protected AbstractButton createFirstButton() {
	AbstractButton button = new JButton();
	format(button);
	button.setIcon(new FirstIcon(2, 24, 24, Color.lightGray));
	button.setRolloverIcon(new FirstIcon(2, 24, 24, Color.white));
	button.setDisabledIcon(new FirstIcon(2, 24, 24, Color.darkGray));
	button.setName("Spinner.firstButton");
	installFirstButtonListeners(button);
	return button;
}
 
Example 11
Source File: LargeNavigationPanelUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
protected Component createNextButton() {
	AbstractButton button = NavigationButtons.createNext();
	format(button);
	button.setIcon(new TriangleIcon(SwingConstants.EAST, 24, 24,
			Color.lightGray));
	button.setRolloverIcon(new TriangleIcon(SwingConstants.EAST, 24, 24,
			Color.white));
	button.setDisabledIcon(new TriangleIcon(SwingConstants.EAST, 24, 24,
			Color.darkGray));
	button.setName(NEXT_BUTTON_NAME);
	installNextButtonListeners(button);
	return button;
}
 
Example 12
Source File: LargeNavigationPanelUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
protected Component createPreviousButton() {
	AbstractButton button = NavigationButtons.createPrev();
	format(button);
	button.setIcon(new TriangleIcon(SwingConstants.WEST, 24, 24,
			Color.lightGray));
	button.setRolloverIcon(new TriangleIcon(SwingConstants.WEST, 24, 24,
			Color.white));
	button.setDisabledIcon(new TriangleIcon(SwingConstants.WEST, 24, 24,
			Color.darkGray));
	button.setName(PREV_BUTTON_NAME);
	installPreviousButtonListeners(button);
	return button;
}
 
Example 13
Source File: NavigationButtons.java    From pumpernickel with MIT License 5 votes vote down vote up
public static void formatNext(AbstractButton button) {
	button.setIcon(createIcon(true, .75f));
	button.setRolloverIcon(createIcon(true, .85f));
	button.setSelectedIcon(createIcon(true, 1f));
	button.setDisabledIcon(createIcon(true, .3f));
	button.setUI(new BevelButtonUI());
	button.setContentAreaFilled(true);
	button.putClientProperty("JButton.segmentPosition", "last");
	button.setBorderPainted(true);
}
 
Example 14
Source File: NavigationButtons.java    From pumpernickel with MIT License 5 votes vote down vote up
public static void formatPrev(AbstractButton button) {
	button.setIcon(createIcon(false, .75f));
	button.setRolloverIcon(createIcon(false, .85f));
	button.setSelectedIcon(createIcon(false, 1f));
	button.setDisabledIcon(createIcon(false, .3f));
	button.setUI(new BevelButtonUI());
	button.setContentAreaFilled(true);
	button.putClientProperty("JButton.segmentPosition", "first");
	button.setBorderPainted(true);
}
 
Example 15
Source File: URLPresenter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes a specified presenter.
 *
 * @param  presenter  presenter to initialize
 */
private void initialize(AbstractButton presenter, boolean useIcons) {

    if (useIcons) {
        // set the presenter's icon:
        Image icon = ImageUtilities.loadImage(
                "org/netbeans/modules/url/urlObject.png");              //NOI18N
        try {
            FileObject file = dataObject.getPrimaryFile();
            icon = FileUIUtils.getImageDecorator(file.getFileSystem()).
                    annotateIcon(icon,
                        BeanInfo.ICON_COLOR_16x16,
                        dataObject.files());
        } catch (FileStateInvalidException fsie) {
            // OK, so we use the default icon
        }
        presenter.setIcon(new ImageIcon(icon));
    }

    /* set the presenter's text and ensure it is maintained up-to-date: */
    NameChangeListener listener = new NameChangeListener(presenter);
    presenter.addPropertyChangeListener(
            WeakListeners.propertyChange(listener, dataObject));
    updateName(presenter);
    /*
     * The above code works with the assumption that it is called
     * from the AWT event dispatching thread (it manipulates
     * the presenter's display name). The same applies to
     * NameChangeListener's method propertyChange(...).
     *
     * At least, both mentioned parts of code should be called from
     * the same thread since method updateText(...) is not thread-safe.
     */

    presenter.addActionListener(this);
    HelpCtx.setHelpIDString(presenter,
                            dataObject.getHelpCtx().getHelpID());
}
 
Example 16
Source File: BasicAudioPlayerUI.java    From pumpernickel with MIT License 4 votes vote down vote up
protected static void setIcon(AbstractButton button, Icon icon) {
	button.setIcon(icon);
	button.setRolloverIcon(new DarkenedIcon(icon, .5f));
	button.setPressedIcon(new DarkenedIcon(icon, .75f));
}
 
Example 17
Source File: AnimationController.java    From pumpernickel with MIT License 4 votes vote down vote up
void setIcon(AbstractButton button, Icon icon) {
	button.setIcon(icon);
	button.setRolloverIcon(new DarkenedIcon(button, .5f));
	button.setPressedIcon(new DarkenedIcon(button, .75f));
}
 
Example 18
Source File: ToolButtonFactory.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
public static AbstractButton createButton(Icon icon, boolean toggle) {
    AbstractButton button = createButton(toggle);
    button.setIcon(icon);
    configure(button);
    return button;
}
 
Example 19
Source File: EditorActionUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void updateButtonIcons(AbstractButton button, Icon icon, boolean useLargeIcon, String iconResource) {
    button.setIcon(icon);

    if (iconResource != null) {
        String base = iconResource;
        String suffix = "";
        int dotIndex;
        if ((dotIndex = iconResource.lastIndexOf('.')) >= 0) {
            suffix = iconResource.substring(dotIndex, iconResource.length());
            base = iconResource.substring(0, dotIndex);
        }
        if (useLargeIcon) {
            base += LARGE_ICON_SIZE_STRING;
        }

        Icon pressedIcon = ImageUtilities.loadImageIcon(base + "_pressed" + suffix, true); // NOI18N
        if (pressedIcon != null) {
            button.setPressedIcon(pressedIcon);
        }
        Icon rolloverIcon = ImageUtilities.loadImageIcon(base + "_rollover" + suffix, true); // NOI18N
        if (rolloverIcon != null) {
            button.setRolloverIcon(rolloverIcon);
        }
        Icon disabledIcon = ImageUtilities.loadImageIcon(base + "_disabled" + suffix, true); // NOI18N
        if (disabledIcon != null) {
            button.setDisabledIcon(disabledIcon);
        } else { // Make disabled icon from regular icon
            button.setDisabledIcon(ImageUtilities.createDisabledIcon(icon));
        }
        Icon selectedIcon = ImageUtilities.loadImageIcon(base + "_selected" + suffix, true); // NOI18N
        if (selectedIcon != null) {
            button.setSelectedIcon(selectedIcon);
        }
        Icon rolloverSelectedIcon = ImageUtilities.loadImageIcon(base + "_rolloverSelected" + suffix, true); // NOI18N
        if (rolloverSelectedIcon != null) {
            button.setRolloverSelectedIcon(rolloverSelectedIcon);
        }
        Icon disabledSelectedIcon = ImageUtilities.loadImageIcon(base + "_disabledSelected" + suffix, true); // NOI18N
        if (disabledSelectedIcon != null) {
            button.setDisabledSelectedIcon(disabledSelectedIcon);
        }
    }
}
 
Example 20
Source File: Utils.java    From iBioSim with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the button's icon and returns the path to it.
 * @param button
 * @param icon
 * @return
 */
public static void setIcon(AbstractButton button, URL icon){

	// set the icon
	button.setIcon(new ImageIcon(icon));
}