Article View: borland.public.jbuilder.java.swing
Article #9594Re: JOptionPane problem (Need Help)
From: Paul Furbacher
Date: Fri, 03 Mar 2000 00:00
Date: Fri, 03 Mar 2000 00:00
43 lines
1959 bytes
1959 bytes
Tal Olier wrote:
> I'm trying a to build a new Java application, and in this application I have
> a class that handle events (which implements ActionListener).
> After I check the getActionCommand() I would like to open a list box with
> options that the user would choose from.
>
> As I understood I should do it with the following:
>
> String s = (String)JOptionPane.showInputDialog(
> null,
> "I am the title",
> JOptionPane.QUESTION_MESSAGE,
> null,
> selVal,
> selVal[3]
> );
>
> My problem is that the variable s holds a string value of the option choosen
> by the user and I need the index of the option in the selVal array.
If the option pane returns string "s", you simply iterate through
the original array, comparing the value of each element in
that array to "s". If you don't want to write the iterative
code to do this, hold the list in a vector and just as you are
setting up the option pane, copy the contents of the vector into
an array:
// assuming you have a vector vList containing your list
String [] list = new String [vList.size()];
vList.copyInto(list);
String s = (String)JOptionPane.showInputDialog(
...,
list,
list[3] );
...
int index = vList.indexOf(s);
if ( index > -1 ) ...
Paul Furbacher (TeamB)
Technical Details
Message-ID:
<38C0237F.A467ADC2@home.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<89o2g0$pio3@bornews.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,230dd878f092e604 X-Google-Attributes: gid111d45,public From: Paul Furbacher <pnf@home.com> Subject: Re: JOptionPane problem (Need Help) Date: 2000/03/03 Message-ID: <38C0237F.A467ADC2@home.com> X-Deja-AN: 592816853 Content-Transfer-Encoding: 7bit References: <89o2g0$pio3@bornews.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Reply-To: pnf@home.com Newsgroups: borland.public.jbuilder.java.swing