-1
I tried to put the image but it’s just enough NullPointerException
, I have tried creating a folder called img
inside the briefcase src
and point there however unsuccessfully too. I don’t know what I might be doing wrong. The image is in the directory.
Follows the code:
public class GuiTeste {
JFrame frame = new JFrame();
JButton bTOrdenar = new JButton();
public void iniciar() {
bTOrdenar.setIcon(new javax.swing.ImageIcon(getClass().getResource("img/iconOrganize.png")));
frame.setSize(520,120);
frame.setLocationRelativeTo(null);
frame.getContentPane().add(BorderLayout.NORTH,bTOrdenar);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
GuiTeste teste= new GuiTeste();
teste.iniciar();
}
}
I also tried the command:
Image img = ImageIO.read(getClass().getResource("img/IconLoad2.bmp")); bTOrdenar.setIcon(new ImageIcon(img));
Please submit a code that is a [mcve] so that it is possible to test and execute.
– user28595
I’m sorry, I already put in the full code
– William Ferreira
Not complete, how do we execute it? I suggest you read the link I sent and follow the directions explained in it.
– user28595
@Carlosheuberger he already clarified in the comments of the answer.
– user28595