2012-05-20 4 views
1

user.Eg에서 선택한 옵션의 색인에 액세스하고 싶습니다. 아래 그림에서 Microsoft 옵션을 선택하면 색인 1이 표시됩니다. 가능합니까? 당신이 "Microsoft"을 (잘 Object는 마이크로 소프트를 보여주는 이상) 얻을 잘Joptionpane에서 색인 얻기

enter image description here

+3

비슷한 질문은 이미 답이 여기에있는 것 같다 // 유래 .com/questions/3074478/index-from-a-string-array-in-a-joptionpane을 선택하는 방법 – bschandramohan

답변

2

쇼 호출의 반환 값으로, 충분히 좋은인가?

인덱스가 필요한 경우 대화 상자에 제공 한 입력 배열에서 해당 반환 값의 인덱스를 찾으십시오. (..) 당신이 showInputDialog를 사용하는 가정 http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#input

:

는 자바 튜토리얼의 입력 섹션을 참조하십시오 HTTP :

Object[] possibilities = {"Broadcom...", "Microsoft"}; 
Object result = JOptionPane.showInputDialog(frame, "Capture Interfaces", "Input", JOptionPane.PLAIN_MESSAGE, icon, possibilities, possibilities[0]); 

if (result != null) { 
    //result is the choosen object, if you need the index even so: 
    int index = 0; 
    for (Object o : possibilities) { 
     if (result == o) 
      break; 
     index++ 
    } 
    //index is now the index... 
}