Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java swing JList beginner question.  RSS feed

 
Ivan Marik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so I am having a hard time with this and I am certain it can't be this hard. What I am doing is creating a library object with some variables including name and an arraylist named songlist. I also have a gui that I created using netbeans click and point IDE which made it really nice but I'm starting to think that I would have less problems just hard coding it in a texteditor. Well this is where the problem starts, so I have the JList in my gui named libList and for testing purposes in my main method I code:

Im using an array instead of a list because it seems like it would be easier. I'll figure out how to use a list once I can get the array to display properly.

String[] str = {"Ha", "ha", "Ha"};
JList<String> list = new JList<>(str);

So here is where I need to link the list and libList somehow and instead of typing in random code I'll wait for some help or hints. What I need to do is get this list to display when program runs in the libList JList frame.

Thanks for any help!

-Ivan
 
Tony Docherty
Bartender
Posts: 3201
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a gui with a List already added to it then you need to add the array elements to that list and not create a new List.

I suggest you read the Java tutorial on how to do this: http://docs.oracle.com/javase/tutorial/uiswing/components/list.html#mutable
 
Campbell Ritchie
Sheriff
Posts: 53769
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We usualy discuss GUI things on a different forum: moving discussion.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!