Java Code Examples for javax.swing.JButton#getIcon()

The following examples show how to use javax.swing.JButton#getIcon() . 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: ActionsTest.java    From netbeans with Apache License 2.0 8 votes vote down vote up
/**
 * Test whether pressed, rollover and disabled 24x24 icons
 * work for SystemAction.
 */
public void testIconsSystemAction24() throws Exception {
    Action saInstance = SystemAction.get(TestSystemAction.class);
    
    JButton jb = new JButton();
    jb.putClientProperty("PreferredIconSize",new Integer(24));
    Actions.connect(jb, saInstance);
    
    Icon icon = jb.getIcon();
    assertNotNull(icon);
    checkIfLoadedCorrectIcon(icon, jb, 4, "Enabled icon");
    
    Icon rolloverIcon = jb.getRolloverIcon();
    assertNotNull(rolloverIcon);
    checkIfLoadedCorrectIcon(rolloverIcon, jb, 5, "Rollover icon");
    
    Icon pressedIcon = jb.getPressedIcon();
    assertNotNull(pressedIcon);
    checkIfLoadedCorrectIcon(pressedIcon, jb, 6, "Pressed icon");
    
    Icon disabledIcon = jb.getDisabledIcon();
    assertNotNull(disabledIcon);
    checkIfLoadedCorrectIcon(disabledIcon, jb, 7, "Disabled icon");
}
 
Example 2
Source File: ActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test whether pressed, rollover and disabled icons
 * work for SystemAction.
 */
public void testIconsSystemAction() throws Exception {
    Action saInstance = SystemAction.get(TestSystemAction.class);
    
    JButton jb = new JButton();
    Actions.connect(jb, saInstance);
    
    Icon icon = jb.getIcon();
    assertNotNull(icon);
    checkIfLoadedCorrectIcon(icon, jb, 0, "Enabled icon");
    
    Icon rolloverIcon = jb.getRolloverIcon();
    assertNotNull(rolloverIcon);
    checkIfLoadedCorrectIcon(rolloverIcon, jb, 1, "Rollover icon");
    
    Icon pressedIcon = jb.getPressedIcon();
    assertNotNull(pressedIcon);
    checkIfLoadedCorrectIcon(pressedIcon, jb, 2, "Pressed icon");
    
    Icon disabledIcon = jb.getDisabledIcon();
    assertNotNull(disabledIcon);
    checkIfLoadedCorrectIcon(disabledIcon, jb, 3, "Disabled icon");
}
 
Example 3
Source File: ActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test whether pressed, rollover and disabled icons
 * work for javax.swing.Action.
 */
public void testIconsAction() throws Exception {
    JButton jb = new JButton();
    Actions.connect(jb, new TestAction());

    Icon icon = jb.getIcon();
    assertNotNull(icon);
    checkIfLoadedCorrectIcon(icon, jb, 0, "Enabled icon");

    Icon rolloverIcon = jb.getRolloverIcon();
    assertNotNull(rolloverIcon);
    checkIfLoadedCorrectIcon(rolloverIcon, jb, 1, "Rollover icon");

    Icon pressedIcon = jb.getPressedIcon();
    assertNotNull(pressedIcon);
    checkIfLoadedCorrectIcon(pressedIcon, jb, 2, "Pressed icon");

    Icon disabledIcon = jb.getDisabledIcon();
    assertNotNull(disabledIcon);
    checkIfLoadedCorrectIcon(disabledIcon, jb, 3, "Disabled icon");
    
    Icon selectedIcon = jb.getSelectedIcon();
    assertNotNull(selectedIcon);
    checkIfLoadedCorrectIcon(selectedIcon, jb, 8, "Selected icon");
    
    Icon rolloverSelectedIcon = jb.getRolloverSelectedIcon();
    assertNotNull(rolloverSelectedIcon);
    checkIfLoadedCorrectIcon(rolloverSelectedIcon, jb, 9, "RolloverSelected icon");

    // no pressedSelected
    
    Icon disabledSelectedIcon = jb.getDisabledSelectedIcon();
    assertNotNull(disabledSelectedIcon);
    checkIfLoadedCorrectIcon(disabledSelectedIcon, jb, 11, "DisabledSelected icon");
}
 
Example 4
Source File: ActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test whether pressed, rollover and disabled 24x24 icons
 * work for javax.swing.Action.
 */
public void testIconsAction24() throws Exception {
    JButton jb = new JButton();
    jb.putClientProperty("PreferredIconSize",new Integer(24));
    Actions.connect(jb, new TestAction());
    
    Icon icon = jb.getIcon();
    assertNotNull(icon);
    checkIfLoadedCorrectIcon(icon, jb, 4, "Enabled icon24");
    
    Icon rolloverIcon = jb.getRolloverIcon();
    assertNotNull(rolloverIcon);
    checkIfLoadedCorrectIcon(rolloverIcon, jb, 5, "Rollover icon24");
    
    Icon pressedIcon = jb.getPressedIcon();
    assertNotNull(pressedIcon);
    checkIfLoadedCorrectIcon(pressedIcon, jb, 6, "Pressed icon24");
    
    Icon disabledIcon = jb.getDisabledIcon();
    assertNotNull(disabledIcon);
    checkIfLoadedCorrectIcon(disabledIcon, jb, 7, "Disabled icon24");

    Icon selectedIcon = jb.getSelectedIcon();
    assertNotNull(selectedIcon);
    checkIfLoadedCorrectIcon(selectedIcon, jb, 12, "Selected icon24");

    Icon rolloverSelectedIcon = jb.getRolloverSelectedIcon();
    assertNotNull(rolloverSelectedIcon);
    checkIfLoadedCorrectIcon(rolloverSelectedIcon, jb, 13, "RolloverSelected icon24");

    // no pressedSelected

    Icon disabledSelectedIcon = jb.getDisabledSelectedIcon();
    assertNotNull(disabledSelectedIcon);
    checkIfLoadedCorrectIcon(disabledSelectedIcon, jb, 15, "DisabledSelected icon24");
}
 
Example 5
Source File: Utils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static JButton createButton(String action, String icon, String tooltip, ActionListener actionlistener) {
    JButton btn = new JButton();
    btn.setActionCommand(action);
    btn.setIcon(getIconByResourceName("/ui/resources/toolbar/" + icon));
    if (btn.getIcon() == null) {
        btn.setText(action);
    }
    btn.setToolTipText("<html>" + action + (tooltip != null ? (" [" + tooltip + "]") : "") + "</html>");
    btn.addActionListener(actionlistener);
    return btn;
}
 
Example 6
Source File: BoxTabbedPaneUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public void formatCloseButton(JTabbedPane tabs, JButton closeButton) {
	if (!(closeButton.getIcon() instanceof MinimalDuoToneCloseIcon)) {
		MinimalDuoToneCloseIcon icon = new MinimalDuoToneCloseIcon(
				closeButton);
		closeButton.setIcon(icon);
		DescendantMouseListener.installForParentOf(closeButton,
				icon.getParentRollover());
	}
	closeButton.setMargin(new Insets(0, 0, 0, 0));
	closeButton.setBorder(new EmptyBorder(0, 0, 0, 0));
}
 
Example 7
Source File: RapidDockingToolbar.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public void add(Action action) {
	JButton button = new JButton(action);
	if (button.getIcon() != null) {
		button.setText(null);
	}
	add(button);
}
 
Example 8
Source File: SnippetNavigator.java    From littleluck with Apache License 2.0 4 votes vote down vote up
private void setButtonAction(JButton button, Action action) {
    Icon icon = button.getIcon();
    button.setAction(action);
    button.setHideActionText(true);
    button.setIcon(icon); // icon gets obliterated when action set!
}
 
Example 9
Source File: SnippetNavigator.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
private void setButtonAction(JButton button, Action action) {
    Icon icon = button.getIcon();
    button.setAction(action);
    button.setHideActionText(true);
    button.setIcon(icon); // icon gets obliterated when action set!
}