我的应用程序构造如下:
- 主窗口允许用户选择要解析的 CSV 文件
- JOptionPane 在选择 CSV 文件后出现,并且 JOptionPane 包含一个带有各种选项的下拉菜单;每个都生成一个单独的窗口
- 目前,在从菜单中进行选择并单击“确定”按钮后,JOptionPane 将关闭
我正在寻找一种方法来强制 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);
}
}