JOptionPane input question
Hi everybody,
I have JOptionPane input dialog in a program to input file names, and I have a lot of text files to input, over 20. They all come from the same folder, the only difference is their names. Does anyone know, is there a way to have the JOptionPane show the last thing I inputted when it comes up again, so I don't have to type the whole file name again. For example (this isn't exactly code, but I'm formatting it that way so it's clear):
String fileMined = the result from the JOptionPane input dialog
fileMined is saved and used to create a button
If the user wants more input the JOptionPane comes up again
Show the previous fileMined, but let the user change part of it
Save thenew string as fileMined
Just to make sure I'm clear, it would be something like:
Type in C:\Text.txt in JOptionPane
Next time JOptionPane comes up, C:\Text.txt is in the input field, and we can just delete "Text" and replace it with whatever other file name we need
If anyone can tell me how to do this, I'd be very grateful!
Thanks,
Jezzica85
Message was edited by:
jezzica85
[1201 byte] By [
jezzica85a] at [2007-10-3 5:10:40]

create a class field
String fileName = "";//give it an empty value, so it is not null
when you show your dialog use the one with parameters (Object message, Object initialSelectionValue)
for initialSelectionValue use fileName (above)
check the value returned from the inputDialog for cancel,x, or escape used to close the dialog
if(returnedValue is not null, or it is not empty) fileName = returnedValue;
Thanks, Michael, that definitely looks like it's what I want, but I can't get it to work, my compiler keeps telling me I have a type mismatch in the initialSelectionValues parameter ( the last parameter). Would you mind please looking at my code and telling me what I did wrong?
Object inputString = new String( "" );
fileMined = JOptionPane.showInputDialog( null, "Input File", null,
JOptionPane.PLAIN_MESSAGE, null, null, ( String )inputString );
Thanks again,
Jezzica85
Thank you Michael, I didn't know there was something with that few parameters. My code still isn't working to put the previous string in the input box, I have a feeling I'm doing something small and silly. So far, I have:
Object inputString = new String( "" );
fileMined = JOptionPane.showInputDialog( "Input File", ( String )inputString );
if( ( fileMined != null ) && ( fileMined != "" ) ) {
inputString = fileMined;
}
So once again, I guess, can you tell what I'm doing wrong?
Thanks again,
Jezzica85