Swing中的非活动JDIalog

时间:2014-10-05 12:47:30

标签: java swing

我制作了两个JDialogs,一个使用Intellij GUI编辑器而另一个不使用。当我尝试打开ChooseEmailAccountDialog时,它显示为活动状态,但在某种程度上停用并隐藏在InboxMain JDialog下。我会很高兴得到任何帮助,我不知道如何解决这个问题。

ChooseEmailAccountDialog

public class ChooseEmailAccountDialog extends JDialog
{
    //Array list of user defined email accounts
    private ArrayList<EmailAccount> emailAccountArrayList;
    private JPanel jPanel1;
    public ChooseEmailAccountDialog(final ArrayList<EmailAccount> emailAccountArrayList)
    {
        this.emailAccountArrayList = emailAccountArrayList;
        setTitle("Choose email account");
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double width = screenSize.getWidth();
        double height = screenSize.getHeight();
        Dimension dim = new Dimension(300,200);
        this.setMinimumSize(dim);
        this.setPreferredSize(dim);
        this.setLocation(new Point((int) width / 2 - this.getWidth() / 2, (int) height / 2 - this.getHeight() / 2));
        jPanel1 = new JPanel();
        GridLayout gridLayout = new GridLayout(emailAccountArrayList.size(),1);
        jPanel1.setLayout(gridLayout);
        //Adding texts on a buttons
        ArrayList<JButton> jButtons = new ArrayList<JButton>();
        for(EmailAccount x: emailAccountArrayList)
        {
            JButton temp = new JButton(x.getEmailAddress());
            temp.addActionListener(new ActionListenerNewMessageButton(temp.getText(),emailAccountArrayList));
            jButtons.add(temp);
        }
        for(JButton x : jButtons)
        {
            jPanel1.add(x);
        }
        this.getContentPane().add(jPanel1);
        this.pack();
        this.setVisible(true);
       ;
    }

}

InboxMain JDialog(使用Intellij GUI编辑器创建):

public class InboxMain extends JDialog
{
    private JPanel contentPane;
    private JTable messagesJTable;
    private JButton newEmailButton;
    private JButton refreshInboxButton;
    private JButton buttonOK;
    //All accounts configured by user
    private ArrayList<EmailAccount> emailAccountArrayList;
    public InboxMain(final ArrayList<EmailAccount> emailAccountArrayList)
    {
        this.emailAccountArrayList = emailAccountArrayList;;
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);
        newEmailButton.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                ChooseEmailAccountDialog chooseEmailAccountDialog = new ChooseEmailAccountDialog(emailAccountArrayList);
                chooseEmailAccountDialog.setVisible(true);
            }
        });
    }

}

而且gif: https://gfycat.com/PositiveGrouchyAnnashummingbird

消息来源:https://github.com/mmajews/Emailer

问题解决了。添加setModal(true)行可以解决问题。

0 个答案:

没有答案