0
How to set value for jlabel java
I know that to set value for the label you must write: Labelname.setValue("string"); But it never work on Jframe on Eclipse.
7 Réponses
+ 2
If you want to define text on your jlabel then use :
labelName1.setText("something");
//labelName must be same as you set the value of your label name //
And you don't want to set text of jlabel then I don't know what value you want to change.!! Please be more clear. :)
0
Thank you my friend, that exactly what I want, but even so it still not working, I have an error "lblNewLabel1 cannot be resolved", do I need to include some library for example?
0
Mohamed Amine Ben Lamine If you are facing cannot resolved error then it should be the problem with your eclipse.
Try updating your eclipse you can find online how to update eclipse IDE
0
But I downloaded Eclipse lately last week, is it normal to have such problem ?
0
JFrame frame = new JFrame("");
JPanel panel = new JPanel();
JLabel label = new JLabel();
label.setText("label text");
panel.add(label);
frame.add(panel);
frame.setSize(300, 300);
frame.setVisible(true);
0
Guys here is my code that didn't work
JButton button = new JButton("+");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lblNewLabel1.setText("Whatever it is");
}
});
0
Your code is fine I'm definitely sure it's something with your java eclipse.
Or check any YouTube video how to solve this error.
Check this link and read all comments that will help you !!
https://stackoverflow.com/questions/15794821/eclipse-error-cannot-be-resolved-to-a-type