2011-01-04 25 views
2

私はこのコードをエラーなく実行しますが、私が計画した方法では実行されていません。私は、「重要!!」というラベルの付いたボタンをクリックすると、「続行」ボタンが表示されない理由を理解しようとしています。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(); 
       } 
      } 
     }); 
     hehePanel.add(closebutton); 
    } 
}); 

hehePanel.add(fButton); 
hehePanel.add(exitButton); 

答えて

5

あなたは、ダイアログが表示しpack()ダイアログの前に行う前にダイアログにすべてのコンポーネントを追加する必要があります。

dialog.setVisible(true)の後のすべてのコードは、ダイアログが閉じられるまで実行されません。

+1

大変感謝しています。 – thegamer

関連する問題