Search code examples
javaswinglistenerjbuttonjlabel

Button VS Image buttons in JAVA


Recently I found out that I can use my images as buttons with mouse listener. What is the main difference between using buttons and images as buttons. What is the main drawback of this option?

Button:

JButton btnNewButton_1 = new JButton("Button");
btnNewButton_1.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent arg0) {
    //Do something          
  }
});

Image:

getJlabel().addMouseListener(new MouseAdapter() {
  @Override
  public void mouseClicked(MouseEvent arg0) {    
    //Do something
  }
});

Solution

  • Although both of them provide similar functionalities, I think that most users are not accustomed to such a thing.

    To the average user (in my opinion at least), buttons should be clicked and images should be looked at. It is like the image provides a means to the user to understand and the button provides a means for the user to act.

    You could throw in Images in JButtons (as explained here), but that being said, I think that from a User Experience point of view you should not use images as buttons unless you really have to, and when you do, I think that you should include specific instructions.