Adding Items to JList in an application during execution that is read from a JextFiel


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Adding Items to JList in an application during execution that is read from a JextFiel

  1. #1
    Join Date
    Dec 2005
    Posts
    4

    Unhappy Adding Items to JList in an application during execution that is read from a JextFiel

    How can I add a item to a list when ever I am running an application ?
    The Item should be read from a JTextField in that application.

  2. #2
    Join Date
    Oct 2005
    Posts
    107
    ???
    not sure what you mean. you can extend AbstractListModel. Then when you want to add something to the list just add it to the underlying data structure you used and call fireContentsChanged on the ListModel

    http://java.sun.com/j2se/1.4.2/docs/...ListModel.html

  3. #3
    Join Date
    Dec 2005
    Posts
    4

    Unhappy

    I mean, If we typed some text in perticular JTextField and when we pressed enter, Then that string must be added to a JList which already contains some elements and previous elements must not be erased.

  4. #4
    Join Date
    Oct 2005
    Posts
    107
    here's some code snippets...

    add an actionlistener to the textfield
    Code:
    _textField.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e) {
    				doTextEntry();
    			}
    		});
    
    protected void doTextEntry() {
      String s = _textField.getText("");
      _textField.setText("");
     
      //put s into your list model data structure
      wordList.add(s)
      //call fireContentsChanged on the list model to repaint gui
      listModel.fireContentsChanged()
    }

Similar Threads

  1. Replies: 2
    Last Post: 08-08-2005, 02:17 PM
  2. Replies: 0
    Last Post: 10-22-2002, 06:38 AM
  3. Adding Items to a SELECT list
    By Brent in forum Web
    Replies: 1
    Last Post: 09-17-2000, 09:44 AM
  4. Replies: 0
    Last Post: 05-03-2000, 03:26 PM
  5. Replies: 0
    Last Post: 03-18-2000, 02:49 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center