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.

5th Oct 2019, 11:41 PM
Med B Amine amine
Med B Amine amine - avatar
7 odpowiedzi
+ 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. :)
6th Oct 2019, 2:13 AM
Chirag Kumar
Chirag Kumar - avatar
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?
6th Oct 2019, 9:39 AM
Med B Amine amine
Med B Amine amine - avatar
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
6th Oct 2019, 10:11 AM
Chirag Kumar
Chirag Kumar - avatar
0
But I downloaded Eclipse lately last week, is it normal to have such problem ?
6th Oct 2019, 12:27 PM
Med B Amine amine
Med B Amine amine - avatar
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);
6th Oct 2019, 12:31 PM
zemiak
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"); } });
12th Oct 2019, 2:08 PM
Med B Amine amine
Med B Amine amine - avatar
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
12th Oct 2019, 2:30 PM
Chirag Kumar
Chirag Kumar - avatar