我的应用程序的结构如下:力的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