How to set Image on JButton in Java Swing, Java Swing Setting Image Icon on JButton


How to set Image on JButton in Java Swing, Java Swing Setting Image Icon on JButton



The Java Swing Provide the JButton for adding an image on the Button this is a call which has diffrent Constructor to do it, and some merhods to do it.

Setting Image By Constructor

JButton btnBack=new JButton(new ImageIcon("back.jpg"));
or
JButton btnBack=new JButton(new ImageIcon("Back","back.jpg"));

Setting Image By Method
JButton btnBack=new JButton();
Image img = getToolkit().createImage("back.jpg");
ImageIcon btnIcon = new ImageIcon(img);

btnBack.setIcon(myIcon);


{ 0 comments... read them below or add one }

Post a Comment