so I have this JButtons to which I add Icons. The Icons are too large initially, so I resize them beforehand, and it works fine. Except that when I resize the window, the JButtons change size, but not the Icons, which is problematic.
Is there a way to have an Icon just fill the JButton it is attached to? Bit of code to make it clearer:
public JewelClass(){
setBackground (new Color (30,30,30));
addActionListener(this);
setLayout(new GridLayout());
ImageIcon icon = new ImageIcon(src/carre.jpg);
setIcon (resizeIcon(icon,60,60));
}
resizeIcon being a personal function, that takes an Icon, a width parameter and a height parameter, and return a resized Icon (obviously). I tried changing the Layout, but it doesn't change anything. I tried getting the width/height of the JButton, but since they don't exist yet when the Icon is added, it doesn't work.
Would you guys have any idea how to get through this? It doesn't have to be an icon, as long as my JButton is filled with the image I give it, it's awesome :)
Thanks!
int margin = 0; Dimension dim = this.getParent().getSize();
without the need to overridegetMinimumSize()
andgetPreferredSize()
since the parent component has its margins already set – Queer