小编the*_*mer的帖子

JDialog模态问题java gui

我有这个代码运行没有任何错误,但它没有按照我计划的方式运行.我想弄清楚当我点击标有"重要!!"的按钮时,为什么我的"继续"按钮没有显示.

唯一显示的是一个空白弹出窗口,它是代码JDialog的一部分,它设置为模态和可见.我只是想不出来.如果有人能帮助我,我会非常感激.

JPanel hehePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT,10,20));
JDialog dialog = new JDialog((JFrame)null);
dialog.getContentPane().add(hehePanel,BorderLayout.CENTER);
JButton hButton = new JButton("important!!");
JButton fButton = new JButton(" on construction !!");
JButton exitButton = new JButton("EXIT CAW ");
hehePanel.add(hButton);
hButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        final JPanel hehePanel = new JPanel();
        final JDialog dialog = new JDialog();
        dialog.getContentPane().add(hehePanel,BorderLayout.PAGE_END);
        dialog.toFront();
        dialog.setModal(true);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
        JButton closebutton = new JButton("Continue");
        closebutton.setActionCommand("continue");
        closebutton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                if (evt.getActionCommand().equals("continue")) {
                    dialog.dispose();
                } …
Run Code Online (Sandbox Code Playgroud)

java user-interface swing modal-dialog jdialog

2
推荐指数
1
解决办法
4338
查看次数

标签 统计

java ×1

jdialog ×1

modal-dialog ×1

swing ×1

user-interface ×1