Here I have shared a way to use image as background icon on JButton.
Code Example:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class simpletest extends JFrame
{
String conversion;
public simpletest()
{
setSize(300,200);
setTitle(“Button Icon”);
setDefaultCloseOperation(EXIT_ON_CLOSE);
ImageIcon iconA = new ImageIcon(“image002.jpg”);
JPanel panel=new JPanel();
getContentPane().add(panel);
panel.setLayout(null);
JButton beep;
beep= new JButton(“Click”,iconA);
beep.setRolloverIcon(iconA);
beep.setBounds(100,60,120,50);
panel.add(beep);
}
public static void main(String args[])
{
simpletest x=new simpletest();
x.setVisible(true);
}
}
OUTPUT:
how come I cant do something like…
ImageIcon iconA = new ImageIcon(“https://allaboutbasic.files.wordpress.com/2010/12/button-icon-java.png?w=302&h=201”);
and get an image from the web?
LikeLiked by 1 person
The URL of the Image will be https://allaboutbasic.files.wordpress.com/2010/12/button-icon-java.png
Thanks.
LikeLike