簡體   English   中英

從JOptionPane輸入對話框中獲取選定的值

[英]Getting selected value from a JOptionPane input dialog

我試圖弄清楚如何從帶有組合框的JOptionPane對話框中獲取選定的值(嗯,有點)。

這是代碼:

String [] locations = { "Brisbane", "Sydney", "Melbourne" };
Object city = (String) JOptionPane.showInputDialog(
    null,
    "Location?",
    "Hills School",
    JOptionPane.PLAIN_MESSAGE,
    null,
    locations,
    locations[0]);

您可能會看到,我實際上並未使用組合框,而這正是我遇到的問題。 它仍然在JOptionPane中顯示為組合框,但是我不能使用getSelectedValue()。 我已經檢查了Java網站,但似乎找不到如何獲得所選值的答案。

有沒有辦法做到這一點,還是我應該從另一個角度來探討JOptionPane?

謝謝

所選值在您的city變量中,根據轉換,該變量為字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM