Java Action SMALL_ICON
Syntax
Action.SMALL_ICON has the following syntax.
static final String SMALL_ICON
Example
In the following code shows how to use Action.SMALL_ICON field.
//from w w w. j av a2 s .c om
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.plaf.metal.MetalIconFactory;
public class Main {
public static void main(String[] a) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Action action = new ShowAction();
JButton button = new JButton(action);
frame.add(button, BorderLayout.CENTER);
frame.setSize(350, 150);
frame.setVisible(true);
}
}
class ShowAction extends AbstractAction {
public ShowAction() {
super("About");
putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_A));
putValue(Action.SMALL_ICON, MetalIconFactory.getFileChooserHomeFolderIcon());
}
public void actionPerformed(ActionEvent actionEvent) {
System.out.println("About Swing");
}
}
Home »
Java Tutorial »
javax.swing »
Java Tutorial »
javax.swing »