-
jLabel is Private
Hello, i need your help as soon as posible.
I am creating a project on Netbeans and java with GUI.
I have many JFrame forms but the problem is this: When i try to change the text to a label from other form i cant because i Private.
e.g: I have 2 JFrame forms (form1 and form2) i try to change the value (setText) to a label on form2 from the code of form1 but it return me that the label is private how can i solve it?
-
create a public setter-method in your form2 class. additional, the form1 need a reference to an instance of form2 !
Code:
class Form2{
private Jlabel label ......
public void setLabelText(String txt){
label.setText(txt);
}
......
}
Code:
class Form1{
.....
form2instance.setLabelText("......");
....
}
-
can you explain it with more details?
The label name is jLabel3 and i want FROM form1 to change jLabel3 of form2.
Thank you.
-
What details do you want? What question do you have about getter and setter methods?
-
My question is:
how to create this "private Jlabel label"
and how to call the method that we create in form2
-
Your question is low on details and this is probably why no one has answered it yet. Please check out the link in my signature below on how to ask smart questions and it will help give you suggestions on the information we would need to be able to give you an answer that could possibly help you.
-
Sorry for that, but English is not my nuture language =\
Now, the private jLabel label; is not correct and compiler show it as fault
Can you write full please?
-
Code:
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new result().setVisible(true);
}
private jLabel3 label;
public void setLabelText(String txt){
label.setText(txt);
}
});
}
I try the code above but when i write "private jLabel3 label;" the compiler return me "cannot find symbol".
I am sure that, this code "private jLabel....." is not the full but eRaaa give me a part. So can anyone help me please?