i have written this code for showing image instead of button following This answer
My code is:
JButton btnCalender;
try {
BufferedImage calendarIcon = ImageIO.read(new File("Calendar_0.jpg"));
btnCalender = new JButton("Calendar", new ImageIcon(calendarIcon));
btnCalender.setBorder(BorderFactory.createEmptyBorder());
btnCalender.setContentAreaFilled(false);
btnCalender.setBounds(244, 177, 129, 36);
frmOptions.getContentPane().add(btnCalender);
btnCalender.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
But image is not showing. The button area is blank. All images are in Project folder. Why This is happening? Please give me solution. Thanks.
Edit: Solution found. My image resulation was too big. I've compressed this into 144*144. Now it is working.