We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,617 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Two part GUI question

Hey Guys,

I am working on a gui and I've got a two part question. I've got a jlist and a couple of buttons to add and remove components from the list. I've got everything working except for the keyListener. When the cursor is on the jList (hasFocus I assume?) and the enter key is pressed, its supposed to do the same thing as the add button and add the text to the list from the text box. I've read a couple of articles about the keyevents but I still done get it.. where or how can I start?

And the second part, I need to save the list to a file when the program is closed and populate the list from that file when the program is launched. I know I need to serialize the jList as it is using the defaultModel. On this one I dont even know where to start. What code do I put in what class and so on.

Thanks for the help!

2
Contributors
1
Reply
23 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
next_tech
Newbie Poster
7 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

hey next_tech,

it seems to me like you should add the keylistenner to the JTextBox and not the JList, since the Enter key is suposed to add something to the list, it wouldn't make much sense to add something that is already there, or am I missing something?

Some source code would definitly help clear things up about your keylistenner question. But my advice at the moment would be "Make sure the listenner is correctly added to the JTextBox component".

As for file writing there are many tutorials easily found through google, such as this one which comes out first. I don't think you would NEED to serialize the JList, but then again telling us what you are storing in it would help!

if it's just a bunch of strings then to keep it simple i'd leave the JList as is and simply write all the items on seperate lines on the text file, and load each line to an item on launch.

Philippe.Lahaie
Posting Whiz
360 posts since Oct 2007
Reputation Points: 103
Solved Threads: 54
Skill Endorsements: 4

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0553 seconds using 2.68MB