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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.