I'm having problems, so I can add a JLabel
with a word before an icon. I put the image in my package, and I passed the path, the problem is that the label is concatenating with String
(the word I put before), and instead of leaving the word + the image, it shows me the path of image.
What would be the correct way to do it?
What I did:
package teste;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class LabelIcone extends JFrame {
public LabelIcone() {
setSize(400, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
ImageIcon icone = new ImageIcon(getClass().getResource("/imagens/icone.png"));
JLabel label = new JLabel("Teste" + icone);
add(label);
}
public static void main(String[] args) {
LabelIcone lbIc = new LabelIcone();
lbIc.setVisible(true);
}
}