Skip to content

Instantly share code, notes, and snippets.

@dejw
Created August 15, 2009 22:38
Show Gist options
  • Select an option

  • Save dejw/168470 to your computer and use it in GitHub Desktop.

Select an option

Save dejw/168470 to your computer and use it in GitHub Desktop.
import javax.swing.JButton;
import javax.swing.ImageIcon;
public class GraphicalButtonFactory {
public static JButton createButton(String normal){
return createButton(new ImageIcon(normal), null, null);
}
public static JButton createButton(String normal, String pressed){
return createButton(new ImageIcon(normal), new ImageIcon(pressed), null);
}
public static JButton createButton(String normal, String pressed, String disabled){
return createButton(new ImageIcon(normal), new ImageIcon(pressed), new ImageIcon(disabled));
}
public static JButton createButton(ImageIcon normal, ImageIcon pressed, ImageIcon disabled){
JButton button = new JButton("");
button.setIcon(normal);
if(pressed != null) button.setPressedIcon(pressed);
if(disabled != null) button.setDisabledIcon(disabled);
button.setBorder(null);
return button;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment