Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-03-2008, 03:22 AM
Member
 
Join Date: Apr 2008
Posts: 34
kewlgeye is on a distinguished road
Adding to JList with Netbeans
Hello,

I am having a really difficult time trying to add a jTextField name and last name to the jList with netbeans, I know that for exit, I can create an action by right mouse clicking and creating an event. This is simple enough, however I have an add button that I am using and I have no idea how to code the add button with netbeans. Can someone please explain to me in detail how to do this.

I looked for tutorials on using netbeans to use the add button to add to a jlist and I found nothing. if someone could give me the instructions on how to do this, or show me the page for netbeans that shows the steps in netbeans to do this I would really appreciate it. Thank you.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-03-2008, 04:35 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Not clear,

You want to add the contents of the textField to JList?

Quote:
I looked for tutorials on using netbeans to use the add button to add to a jlist and I found nothing.
NetBeans doesn't support that feature(The programmer should do it)... it only initializes the contents when the ClassLoader loads that class.
Not dynamic...

try to use DefaultListModel, have experiments on it....
THere is a JList constructor that has a parameter ListModel...
You can pass that DefaultListModel to that parameter....

You may play with that.....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-03-2008, 07:09 AM
Member
 
Join Date: Apr 2008
Posts: 34
kewlgeye is on a distinguished road
Adding to JList with Netbeans
Ok, I don't really understand where this defaultlistmodel goes, and

THere is a JList constructor that has a parameter ListModel...
I read about this but I keep forgetting what constructors are and a parameter?

do I do something like this

public class defaultlist {
public void defaultListModel() {
listmodel.setjlist1.(jTextField1)
listmodel.setjlist1.(jTextField2)
}
}

and then in the add button actionperformed event
do this

new defaultListModel();
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-03-2008, 09:41 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
No....

Something like,

Code:
class MyMainClass{ DefaultListModel dlm = new DefaultListModel(); JList jlist = new JList( dlm ); //invoke this when add button fired private static final void addList(){ dlm.addElement((Object)jTextField1); // add name dlm.addElement((Object)jTextField2); // add lastname } }
and observe what happens to jlist...
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 06-03-2008 at 09:49 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-03-2008, 09:01 PM
Member
 
Join Date: Apr 2008
Posts: 34
kewlgeye is on a distinguished road
Ok I put this code in the jbutton section and I kept receiving an error that said "Illegal start of expression" I don't know enough to see anything wrong with this. Netbeans didn't say anything else.

Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //invoke this when add button fired private static final void addList(){ dlm.addElement((Object)jTextField1); // add name dlm.addElement((Object)jTextField2); // add lastname } }
and this code I put at the very top of the code, their is more like the rest of the GUI, but I didn't paste it because its too long.


Code:
package editor; import javax.swing.JList; import javax.swing.*; /** * * @author Philip */ class MyMainClass{ DefaultListModel dlm = new DefaultListModel(); JList jlist = new JList( dlm ); } public class NewJFrame extends javax.swing.JFrame { /** Creates new form NewJFrame */ public NewJFrame() { initComponents(); }
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-03-2008, 09:10 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
How then could i do, such a wicked thing, and sin against the netbeans...

after the button clicked, the method
Quote:
jButton1ActionPerformed
should be invoked....

And? i didn't say put that sample method to that actionPerformed...

Code:
eg. private void jButton1ActionPerformed(netbeans style) { addList(); }
put that addList beside those existing methods in your main class

What i mean to MyMainClass is the class you've coded where the main method exists....
I assumed you textFields are also in that main class...
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 06-03-2008 at 09:13 PM.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-03-2008, 09:21 PM
Member
 
Join Date: Apr 2008
Posts: 34
kewlgeye is on a distinguished road
Thank you for your help. Let me show you what I did.



I declared private DefaultListModel lm = newDefaultListModel(); with the rest of my declared buttons and textfields etc...

Then I went to the jlist properties section and clicked on the model section and typed in lm after selecting custom code. and then just added the elements to the add button after creating an event actionperformed by right clicking on the add button, selecting events, then actionperformed and typing in the following code.

lm.addElement(jTextField1.getText()); etc... for the rest of the textfields

I tryed doing this yestereday but I was trying to select component and then I was trying to bind. I go it now though, so if any other newbies like myself need help with something similar hopefully they will find my post, since I was looking for hours for a post like this.


Thank you again for your effort.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JList and JPanels JetsYanks New To Java 3 05-12-2008 05:56 AM
searching within a JList newtojava7 New To Java 1 03-10-2008 01:12 AM
Adding Business Methods to an EJB in NetBeans JavaForums NetBeans 0 07-31-2007 12:13 AM
Help with JList Albert NetBeans 1 07-13-2007 04:42 PM
add a jlist column Alan JCreator 1 05-28-2007 05:51 AM


All times are GMT +3. The time now is 06:18 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org