Results 1 to 4 of 4
  1. #1
    vagf is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default public jTextField ?

    Ok simple question! I have a swing jFrame in a netbeans java application project and a jTextField inside of it. Is there any possible way of retrieving the text from the textField using another class? Obviously i cannot do that because the textField is declared private in swing awt but i was wondering if there is any way around it.

    Thanks in advance!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    Add a public getter method that can get the contents and return it.

    Are these Java SE classes you are talking about? The lowercase j makes me wonder.

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    @Norms - maybe its the component name like jTextField1, jTextField2 and so on.
    It is the name being assign by netbeans at design time but it can be change.

    @OP - you also have to create instance of that class then call the getter method
    Java Code:
    public class ClassA
    {
        ...
        public String getTextFieldText()
        {
            jTextField1.getText();
        }
    }
    
    public class ClassB
    {
        ...
        ClassA aClassA = new ClassA();
        private void textFromOtherClass()
        {
            aClassA.getTextFieldText();
        }
    }
    Last edited by mine0926; 06-07-2011 at 08:37 AM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by mine0926 View Post
    It is the name being assign by netbeans at design time but it can be change.
    Should be changed.

    db

Similar Threads

  1. public @interface ??
    By alexoffspring in forum New To Java
    Replies: 4
    Last Post: 02-15-2011, 10:13 AM
  2. public variables?
    By dyelax in forum New To Java
    Replies: 9
    Last Post: 12-27-2010, 11:17 PM
  3. Replies: 1
    Last Post: 12-04-2010, 05:41 PM
  4. Replies: 5
    Last Post: 06-26-2009, 03:03 AM
  5. Replies: 1
    Last Post: 01-30-2009, 06:44 PM

Posting Permissions

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