showOptionDialog with initial focus on Yes

i am using showOptionDialog with OPTION_YES_NO, i want the default focus to be on No button instead of Yes.

i tried

Object[] options = {"Yes","No"};

(JOptionPane.showOptionDialog(this,"abc","Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[1])== JOptionPane.YES_OPTION)) {//do something}

but still focus is on Yes..please help
[407 byte] By [zulqernain] at [2007-11-20 11:32:08]
# 1 Re: showOptionDialog with initial focus on Yes
That's because in java the first element of an array is at index 0. You are telling it to set the focus to array element 1 which is "No".

Object[] options = {"Yes","No"};

if (JOptionPane.showOptionDialog(this,"abc","Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0])== JOptionPane.YES_OPTION)) {//do something}
keang at 2007-11-10 2:14:05 >
# 2 Re: showOptionDialog with initial focus on Yes
thanks for your reply.
yes i know the first element of the array is 0, i want the focus on 'No' thats why i said options[1] instead of options[0]..but till the focus is on Yes. i dont know why
zulqernain at 2007-11-10 2:15:07 >
# 3 Re: showOptionDialog with initial focus on Yes
Sorry zulqernain, I was in a hurry and misread your post. I've tried it here and it works.

BTW the code you've posted doesn't compile which suggests it isn't the code you are running so try cutting and pasting the following into your program and see if that works.

if (JOptionPane.showOptionDialog(null,"abc","Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[1]) == JOptionPane.YES_OPTION)
{
// do something
}
keang at 2007-11-10 2:16:06 >
# 4 Re: showOptionDialog with initial focus on Yes
i am using JDK1.3.1 i think may be its not working due to that. Is there any way arround?
i tried on latest JDK version and it worked
zulqernain at 2007-11-10 2:17:03 >
# 5 Re: showOptionDialog with initial focus on Yes
i am using JDK1.3.1 I didn't realise people were still using jdk1.3.1.
i think may be its not working due to that. Is there any way arround?Not that I know of (or can remember) other than writing your own dialog.

I suspect it's unlikely that many people will be able to help you with this as this is such an old version of Java. I suppose upgrading is out of the question?
keang at 2007-11-10 2:18:13 >