I have public static variable in a JFrame. I have created a JLabel in another JFrame. I want to set the JLabel text to that variable. when I create the JLabel from netbeans, it create autogenerated code that can’t be changed. I used netbeans 7.2.
I can change the JLabel using myJLabel.setText(JFrame.variableName);. but the problem is auto generated code doesn’t allow me to edit above code snippet.
I would like to set the text to variable name by setting in property panel rather changing above code.
Is there a way to set the dynamic text using property panel?
P.S. - I noticed in property panel, we can set jLabel value from existing component but these components reside in same JFrame. My variable reside in another JFrame
You have two choices that I can see.
One, you simple set the text of the label after the call to
initComponentOr…
myJLabel.setText(JFrame.variableName);. Remember, this code is inserted inline, so it must be well formatted and compilableWhich then produces something like…
NB- Make sure you clear the default text from the label 😉