Results 1 to 8 of 8
  1. #1
    nipuna's Avatar
    nipuna is offline Member
    Join Date
    Sep 2010
    Location
    Sri Lanka
    Posts
    5
    Rep Power
    0

    Wink Adding List to JTextField

    I went through the Java2sAutoTextField class but i can't add it in to a jframe. :mad::mad::mad:

    Heres a part of code i extracted from
    Auto Complete JTextField (Swing / AWT / SWT / JFace forum at JavaRanch)

    can anybody help???? :confused::confused::confused:

    also i tried out JSuggestField @ JSuggestField - The JTextField that makes suggestions | rakudave.ch but i can't add it from netbeans palette.

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Welcome to the forum.

    You may wish to show what you've tried and also give a bit more detail on what you're trying to achieve and what you current problem is in this attempt.

  3. #3
    nipuna's Avatar
    nipuna is offline Member
    Join Date
    Sep 2010
    Location
    Sri Lanka
    Posts
    5
    Rep Power
    0

    Default

    I want to auto generate values for a jtextfield when inserting values in a jframe.
    I found this Java2sAutoTextField method and called it in a jframe constructor like below

    List possible = new ArrayList();
    possible.add("Austria");
    possible.add("Italy");
    possible.add("Croatia");
    possible.add("Hungary");
    Java2sAutoTextField autoCompleter = new Java2sAutoTextField(possible);


    Auto Complete JTextField (Swing / AWT / SWT / JFace forum at JavaRanch)

    But i have no idea how to call it in jtextfield??????????

  4. #4
    nipuna's Avatar
    nipuna is offline Member
    Join Date
    Sep 2010
    Location
    Sri Lanka
    Posts
    5
    Rep Power
    0

    Default

    I want my txtEmpName jtextfield to be autofilled when i insert part of employees name. which acts as a search.

    I want this textbox to be autofilled when i insert the empName

    Currently i do this like
    Inside jframe

    txtEmpName.setText(e.getEmpName(empId));


    getEmpName Method
    public String getEmpName(String empId) throws SQLException, OperationFailed, InvalidldException
    rs = et.select(" fName, lName");
    {
    String name="";
    ResultSet rs;
    rs = et.select(" fName, lName");
    rs.beforeFirst();
    if(rs.next()){
    name = rs.getString(1) + " " + rs.getString(2);
    }

    return name;
    }

    Screen Shot>>>

  5. #5
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Let's simplify the issue:

    1) Are you able to add a JTextField to a Swing GUI so that it displays? It appears that you would add a Java2sAutoTextField to your GUI in exactly the same way, the only difference being that you'd initialize the Java2sAutoTextField object with a java.util.List first. And I don't mean via NetBeans drag and drop but rather by hand-crafted Swing code?
    2) Have you tried the code that was suggested in the CodeRanch forum, to create the java.util.List and then construct the Java2sAutoTextField object with that List?
    3) When you've tried to do this, what specific problems are you having? Can you show your code attempt?

  6. #6
    nipuna's Avatar
    nipuna is offline Member
    Join Date
    Sep 2010
    Location
    Sri Lanka
    Posts
    5
    Rep Power
    0

    Default

    thanks for the conversation curm,

    1. yes i was able to add a jtextfield to the jframe and i initiated the Java2sAutoTextField as given in Auto Complete JTextField (Swing / AWT / SWT / JFace forum at JavaRanch)

    2. yes. i initiated below inside the jframe constructor.

    List possible = new ArrayList();
    possible.add("Austria");
    possible.add("Italy");
    possible.add("Croatia");
    possible.add("Hungary");
    Java2sAutoTextField autoCompleter = new Java2sAutoTextField(possible);

    3. the problem arise is even though i have initiated the java2sautotextfield how can i put this auto completing to the jtextfield????????????

  7. #7
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by nipuna View Post
    thanks for the conversation curm,

    1. yes i was able to add a jtextfield to the jframe and i initiated the Java2sAutoTextField as given in Auto Complete JTextField (Swing / AWT / SWT / JFace forum at JavaRanch)

    2. yes. i initiated below inside the jframe constructor.

    List possible = new ArrayList();
    possible.add("Austria");
    possible.add("Italy");
    possible.add("Croatia");
    possible.add("Hungary");
    Java2sAutoTextField autoCompleter = new Java2sAutoTextField(possible);

    3. the problem arise is even though i have initiated the java2sautotextfield how can i put this auto completing to the jtextfield????????????
    You don't. You use a Java2sAutoTextField object in place of a JTextField. If you look carefully at the Java2sAutoTextField code, you'll see that it in fact extends JTextField, and so it is supposed to be used as a substitute for JTextField, as a kind of "smart" JTextField.

  8. #8
    nipuna's Avatar
    nipuna is offline Member
    Join Date
    Sep 2010
    Location
    Sri Lanka
    Posts
    5
    Rep Power
    0

    Default

    Thanks it now works, i just had to replace the Java2sAutoTextField instead of JTextField. As you said the problem is i didn't went through the source code of Java2sAutoTextField.

    Now i'm trying to connect my database to the coding, Thanks it was a big help

Similar Threads

  1. Adding new fonts to the list of available font??
    By Stephen Douglas in forum NetBeans
    Replies: 15
    Last Post: 04-18-2010, 02:33 PM
  2. Adding jTextField() content to the database?
    By Stephen Douglas in forum New To Java
    Replies: 12
    Last Post: 04-08-2010, 09:50 AM
  3. adding list to an array element
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 09-25-2008, 04:23 AM
  4. Adding List to MIDlet Display
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-23-2007, 02:07 PM
  5. adding a variable in order to a list
    By Jrr in forum New To Java
    Replies: 2
    Last Post: 11-19-2007, 01:10 AM

Tags for this Thread

Posting Permissions

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