Results 1 to 8 of 8
  1. #1
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default 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?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    create a public setter-method in your form2 class. additional, the form1 need a reference to an instance of form2 !

    Java Code:
    class Form2{
     private Jlabel label ......
    
     public void setLabelText(String txt){
        label.setText(txt);
    }
    ......
    }
    Java Code:
    class Form1{
    .....
    form2instance.setLabelText("......");
    ....
    }

  3. #3
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    can you explain it with more details?

    The label name is jLabel3 and i want FROM form1 to change jLabel3 of form2.
    Thank you.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    My question is:
    how to create this "private Jlabel label"
    and how to call the method that we create in form2

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  7. #7
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    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?

  8. #8
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    Java 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?

Similar Threads

  1. Anyone else get this private message?
    By Fubarable in forum New To Java
    Replies: 20
    Last Post: 03-18-2011, 11:26 AM
  2. Replies: 7
    Last Post: 06-28-2010, 07:52 AM
  3. Adding a JLabel to a JPanel - jlabel not showing
    By Bongeh in forum New To Java
    Replies: 17
    Last Post: 04-06-2010, 11:02 PM
  4. private
    By Gary_10 in forum New To Java
    Replies: 1
    Last Post: 01-29-2010, 12:42 AM
  5. private array
    By tnght in forum New To Java
    Replies: 10
    Last Post: 12-05-2009, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •