gpt4 book ai didi

java - 强制 JOptionPane 保持打开状态

转载 作者:行者123 更新时间:2023-12-01 17:26:10 24 4
gpt4 key购买 nike

我的应用程序的构造如下:

  • 主窗口允许用户选择要解析的 CSV 文件
  • 选择 CSV 文件后会出现 JOptionPane,并且 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);
}
}

最佳答案

I would like for the window with the choices to remain open even after the user has selected an option so that they can select another option if they wish. How do I get the JOptionPane to remain open instead of its default behavior where it closes once a drop-down value is selected?

关于java - 强制 JOptionPane 保持打开状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14821667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com