Java examples for Swing:JButton
Java ImageIcon class supports GIF, JPEG, or PNG image.
The following snippet of code shows how to create buttons with icons:
import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; public class Main { public static void main(String[] args) { // Create icons Icon previousIcon = new ImageIcon("C:/images/previous.gif"); Icon nextIcon = new ImageIcon("C:/images/next.gif"); // Create buttons with icons JButton previousButton = new JButton("Previous", previousIcon); JButton nextButton = new JButton("Next", nextIcon); }/*w w w . j a va 2 s . co m*/ }