List of usage examples for javax.swing AbstractButton setRequestFocusEnabled
public void setRequestFocusEnabled(boolean requestFocusEnabled)
JComponent
should get focus. From source file:org.openscience.jmol.app.Jmol.java
/** * Create a button to go inside of the toolbar. By default this * will load an image resource. The image filename is relative to * the classpath (including the '.' directory if its a part of the * classpath), and may either be in a JAR file or a separate file. * * @param key The key in the resource file to serve as the basis * of lookups./*from w w w . j av a 2s . co m*/ * @return Button */ protected AbstractButton createToolbarButton(String key) { ImageIcon ii = JmolResourceHandler.getIconX(key + "Image"); AbstractButton b = new JButton(ii); String isToggleString = JmolResourceHandler.getStringX(key + "Toggle"); if (isToggleString != null) { boolean isToggle = Boolean.valueOf(isToggleString).booleanValue(); if (isToggle) { b = new JToggleButton(ii); if (key.equals("rotate")) buttonRotate = b; toolbarButtonGroup.add(b); String isSelectedString = JmolResourceHandler.getStringX(key + "ToggleSelected"); if (isSelectedString != null) { boolean isSelected = Boolean.valueOf(isSelectedString).booleanValue(); b.setSelected(isSelected); } } } b.setRequestFocusEnabled(false); b.setMargin(new Insets(1, 1, 1, 1)); Action a = null; String actionCommand = null; if (key.endsWith("Script")) { actionCommand = JmolResourceHandler.getStringX(key); a = executeScriptAction; } else { actionCommand = key; a = getAction(key); } if (a != null) { b.setActionCommand(actionCommand); b.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(b)); b.setEnabled(a.isEnabled()); } else { b.setEnabled(false); } String tip = guimap.getLabel(key + "Tip"); if (tip != null) { b.setToolTipText(tip); } return b; }