I am creating a JButton which includes a specific ImageIcon. The main issue is that the original icon size is much bigger than the button size. As result when the button is displayed, only part of the icon can be seen. What is the method that "resize" an ImageIcon i n order to make it fit inside a JButton?
Simply delete the frame. setPreferredSize() and the buttons will be small (the frame size will be determined by the preferred sizes of inner components by calling frame.
Now, to use this method in your example code: JFrame frame2 = new JFrame("Tauler Joc"); JPanel panell = new JPanel(); ImageIcon icon = new ImageIcon("king. jpg"); JButton jb= new JButton(); jb. setBounds(200,200,700,700); panell.
To change the font in java swing: name_Button. setFont(new FontUIResource(String name, int style, int size)); name the font name.
Image img = icon.getImage() ; Image newimg = img.getScaledInstance( NEW_WIDTH, NEW_HEIGHT, java.awt.Image.SCALE_SMOOTH ) ; icon = new ImageIcon( newimg );
from http://www.coderanch.com/t/331731/GUI/java/Resize-ImageIcon
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With