1
I’m having trouble creating an icon button in java, I’ve looked at several tutorials, but I can’t make it work.
Note: I am using eclipse, Windows 10. The folder that is the image is src where the Main class file is.
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
Icon imageIcon = new ImageIcon("flag.png");
frame.add(new JButton("Flag",imageIcon));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,400);
frame.setVisible(true);
}
}
Something like that? https://answall.com/q/15490/3117
– Math