Hi how can I fit the size of a ImageIcon to a JButton? I want to adjust the size of the ImageIcon to the size of the Button
JFrame frame2 = new JFrame("Tauler Joc");
JPanel panell = new JPanel();
ImageIcon icon = new ImageIcon("king.jpg");
JButton jb= new JButton(icon);
jb.setBounds(200,200,700,700);
panell.add(jb);
frame2.add(panell);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
You can do it this way by simply adding a little method to your project:
Now, to use this method in your example code:
If you just want the image and no border just set the offset variable to 0 or get rid of the offset variable altogether.