我的應用程序的結構如下:力的JOptionPane保持開放
- 主窗口允許用戶選擇CSV文件進行解析
- 選擇CSV文件後的JOptionPane出現,JOptionPane的含有滴具有各種選擇的下拉菜單;其中每產生一個單獨的窗口
- 目前,選擇從菜單進行和「OK」按鈕被點擊
我正在尋找一種方式來迫使JOptionPane中保持開放這樣用戶可以根據需要選擇不同的東西。我想通過單擊右上角的「X」來關閉JOptionPane。如果使用JOptionPane並不是實現這一目標的最佳方法,那麼我也可以開放其他可能性來實現類似的結果。
這裏是代碼相關的塊我工作:
try
{
CSVReader reader = new CSVReader(new FileReader(filePath), ',');
// Reads the complete file into list of tokens.
List<String[]> rowsAsTokens = null;
try
{
rowsAsTokens = reader.readAll();
}
catch (IOException e1)
{
e1.printStackTrace();
}
String[] menuChoices = { "option 1", "option 2", "option 3" };
String graphSelection = (String) JOptionPane.showInputDialog(null,
"Choose from the following options...", "Choose From DropDown",
JOptionPane.QUESTION_MESSAGE, null,
menuChoices, // Array of menuChoices
menuChoices[0]); // Initial choice
String menuSelection = graphSelection;
// Condition if first item in drop-down is selected
if (menuSelection == menuChoices[0] && graphSelection != null)
{
log.append("Generating graph: " + graphSelection + newline);
option1();
}
if (menuSelection == menuChoices[1] && graphSelection != null)
{
log.append("Generating graph: " + graphSelection + newline);
option2();
}
if (menuSelection == menuChoices[2] && graphSelection != null)
{
log.append("Generating graph: " + graphSelection + newline);
option3();
}
else if (graphSelection == null)
{
log.append("Cancelled." + newline);
}
}
請發佈您的代碼。 – Aubin 2013-02-11 22:03:45
可能會更好地把你的下拉菜單放在不同的選框中,這會給你更多的行爲選項 – 2013-02-11 22:05:51
我也注意到你正在使用'=='比較'字符串'。這不是'Java'中的方法。你應該使用'equals()'方法來代替:'menuSelection.equals(menuChoice [0])' – Michael 2013-02-11 23:29:26