如何在单独的 JOptionPane 中显示不同的数组

How to display different Arrays in separate JOptionPane

我正在尝试制作 3 JOptionPane。每个都必须显示一些数据数组。

第一个必须显示firstDataArray的20条信息

只有当用户点击取消时我要弹出新的JOptionPane它必须显示secondDataArray等的信息...

我面临的问题是,当用户在第一个 JOptionPane 上单击取消时,第二个 JOptionPane 正在显示 firstDataArray 和 secondDataArray 的所有信息(我想将 2 个分开JOptionPane 使用不同的数组列表)

同理取消第二个JOptionPane底部,第三个JoptionPane显示3个数据数组的所有信息

我做错了什么?

非常感谢,

低音

      String[] firstDataArray= new String[20];
            String[] secondDataArray= new String[20];
            String[] thirdDataArray= new String[20];

            firstDataArray= ClassA.getFirstData();
            secondDataArray= ClassA.getSecondData();
            thirdDataArray= ClassA.getThirdData();

            StringBuilder textRegion = new StringBuilder();

            String txt = JOptionPane.showInputDialog(null,
                    textRegion.append(Arrays.toString(firstDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choose Option)",
                    JOptionPane.PLAIN_MESSAGE);
//If the user click cancel , show the other array in a new JoptionPane   
            if (txt == null) {

                txt = JOptionPane.showInputDialog(null,
                        textRegion.append(Arrays.toString(secondDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choisir municipalite (Chose option)",
                        JOptionPane.PLAIN_MESSAGE);


//If the user click cancel again , show the other array in a third JoptionPane  
                    if (txt == null) {

                    txt = JOptionPane.showInputDialog(null,
                            textRegion.append(Arrays.toString(thirdDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Chose Option)",
                            JOptionPane.PLAIN_MESSAGE);
                    if (txt == null) {

                    } else {
                        setNomMunicipalite(txt);
                    }

                } else {
                    setNomMunicipalite(txt);
                }
            } else {
                setNomMunicipalite(txt);
            }

您总是将每个数组附加到相同的 StringBuilder

每个使用一个新的JOptionPane

        StringBuilder textRegion = new StringBuilder();

        String txt = JOptionPane.showInputDialog(null,
                textRegion.append(Arrays.toString(firstDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choose Option)",
                JOptionPane.PLAIN_MESSAGE);
        //If the user click cancel , show the other array in a new JoptionPane   
        if (txt == null) {
            textRegion = new StringBuilder(); // <--- 
            txt = JOptionPane.showInputDialog(null,
                    textRegion.append(Arrays.toString(secondDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choisir municipalite (Chose option)",
                    JOptionPane.PLAIN_MESSAGE);


                //If the user click cancel again , show the other array in a third JoptionPane  
                if (txt == null) {
                textRegion = new StringBuilder(); // <---

                txt = JOptionPane.showInputDialog(null,
                        textRegion.append(Arrays.toString(thirdDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Chose Option)",
                        JOptionPane.PLAIN_MESSAGE);
                if (txt == null) {

                } else {
                    setNomMunicipalite(txt);
                }

            } else {
                setNomMunicipalite(txt);
            }
        } else {
            setNomMunicipalite(txt);
        }