2010-11-21 22 views
0

私のプログラムのある時点で、JDialogが開き、プログラムの実行中に何が起こっているかに関する情報が表示されます。いくつかのラベルと進行状況バーがありますが、ダイアログウィンドウが開いても何も表示されません。ここで私のカスタムJDialogが表示されますが、空白です

は、カスタムダイアログとそのコンストラクタです:

public class DataMiner implements ActionListener 
{ 
    private Hashtable<Integer, GISNode> nodeTable; 
    private Hashtable<Integer, GISLink> linkTable; 
    private int numLinesIgnored; 
    private int numLinesProcessed; 
    private int numNodes; 
    private int numLinks; 
    private int numDuplicates; 
    private int numFailedGeoCodingRequests; 
    private boolean cancelled; 

// window objects 
    private JDialog window; 
    private JLabel LinesIgnored; 
    private JLabel LinesProcessed; 
    private JLabel Nodes; 
    private JLabel Links; 
    private JLabel Duplicates; // tracks the number of equivalent data entries found. 
    private JLabel FailedGeoCodingRequests; 
    private JProgressBar progressBar; 
    private JButton cancelButton; 

    public DataMiner(JFrame parentWindow) 
    { 
     nodeTable = new Hashtable<Integer, GISNode>(1000); 
     linkTable = new Hashtable<Integer, GISLink>(1000); 

     numLinesIgnored = 0; 
     numLinesProcessed = 0; 
     numNodes = 0; 
     numLinks = 0; 
     numDuplicates = 0; 
     numFailedGeoCodingRequests = 0; 
     cancelled = false; 

     LinesIgnored = new JLabel(); 
     LinesProcessed = new JLabel(); 
     Nodes = new JLabel(); 
     Links = new JLabel(); 
     Duplicates = new JLabel(); 
     FailedGeoCodingRequests = new JLabel(); 
     cancelButton = new JButton("Cancel"); 
     progressBar = new JProgressBar(); 

     updateLabels(); // assigns a formatted string to each JLabel 
     cancelButton.addActionListener(this); 

    // initialize window 
     window = new JDialog(parentWindow); 
     window.setResizable(false); 
     window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 

     Container content = window.getContentPane(); 
     content.setLayout(new GridLayout(7,1)); 
     content.add(LinesProcessed); 
     content.add(Nodes); 
     content.add(Links); 
     content.add(Duplicates); 
     content.add(LinesIgnored); 
     content.add(FailedGeoCodingRequests); 
     content.add(progressBar); 
     JPanel p1 = new JPanel(); 
     p1.add(new JLabel("")); // takes up space 
     p1.add(cancelButton); 
     content.add(p1); 
     window.pack(); 
     window.setLocationRelativeTo(parentWindow); 
     window.setVisible(true); 
    } 

    (rest of the class...) 
} 

このウィンドウが開いたら、プログラムの残りの部分は通常通り実行し続け、ちょうどこのウィンドウは空白になっています。私は何か不足していますか?

+0

ダイアログがまったく表示されていますか?もしそうでなければ、まずJDialogのsetSize()を使ってみてください。 –

+0

@pouncep:それは何も表示されません。 – Max

+0

['invokeLater'](http://download.oracle.com/javase/tutorial/uiswing/concurrency/initial.html)を使用して、イベントディスパッチスレッドから' window.setVisible(true) 'を呼び出してみてください。 – casablanca

答えて

1

あなたはGUIにEventDispatchThreadを、ブロックしているために自分自身を再描画することはできません。詳細は、ConcurrencyのSwingチュートリアルのセクションを参照してください。

あなたは適切なSSCCEを提供していないので、推測以上のことはできません。

+0

ありがとうございました。これは私が必要とするもののように見えます。 – Max

+0

デバッグ時にコード全体にSwingUtilities.isEventDispatchThread()コールを振り分けると便利です。 –

0

これは本当に奇妙です。このコードは私にとってはうまく動作します。空のメインウィンドウ(右)と「ポップアップ」の子フレームウィンドウ(あなたにとってはうまくいきません)を示しています。私はUbuntuの下のNetBeans 6.8およびJava 1.6を使用しました:おそらく

package javaapplication2; 

import java.awt.Container; 
import java.awt.GridLayout; 
import javax.swing.JButton; 
import javax.swing.JDialog; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JProgressBar; 

public class MainFrame extends javax.swing.JFrame { 

    private int numLinesIgnored; 
    private int numLinesProcessed; 
    private int numNodes; 
    private int numLinks; 
    private int numDuplicates; 
    private int numFailedGeoCodingRequests; 
    private boolean cancelled; 

// window objects 
    private JDialog window; 
    private JLabel LinesIgnored; 
    private JLabel LinesProcessed; 
    private JLabel Nodes; 
    private JLabel Links; 
    private JLabel Duplicates; // tracks the number of equivalent data entries found. 
    private JLabel FailedGeoCodingRequests; 
    private JProgressBar progressBar; 
    private JButton cancelButton; 

    /** Creates new form MainFrame */ 
    public MainFrame() { 
     initComponents(); 

     JFrame parentWindow = this; 


     numLinesIgnored = 0; 
     numLinesProcessed = 0; 
     numNodes = 0; 
     numLinks = 0; 
     numDuplicates = 0; 
     numFailedGeoCodingRequests = 0; 
     cancelled = false; 

     LinesIgnored = new JLabel(); 
     LinesProcessed = new JLabel(); 
     Nodes = new JLabel(); 
     Links = new JLabel(); 
     Duplicates = new JLabel(); 
     FailedGeoCodingRequests = new JLabel(); 
     cancelButton = new JButton("Cancel"); 
     progressBar = new JProgressBar(); 

    // initialize window 
     window = new JDialog(parentWindow); 
     window.setResizable(false); 
     window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 

     Container content = window.getContentPane(); 
     content.setLayout(new GridLayout(7,1)); 
     content.add(LinesProcessed); 
     content.add(Nodes); 
     content.add(Links); 
     content.add(Duplicates); 
     content.add(LinesIgnored); 
     content.add(FailedGeoCodingRequests); 
     content.add(progressBar); 
     JPanel p1 = new JPanel(); 
     p1.add(new JLabel("")); // takes up space 
     p1.add(cancelButton); 
     content.add(p1); 
     window.pack(); 
     window.setLocationRelativeTo(parentWindow); 
     window.setVisible(true); 
    } 

    /** This method is called from within the constructor to 
    * initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is 
    * always regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code"> 
    private void initComponents() { 

     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGap(0, 400, Short.MAX_VALUE) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGap(0, 300, Short.MAX_VALUE) 
     ); 

     pack(); 
    }// </editor-fold> 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String args[]) { 
     java.awt.EventQueue.invokeLater(new Runnable() { 
      public void run() { 
       new MainFrame().setVisible(true); 
      } 
     }); 
    } 

    // Variables declaration - do not modify 
    // End of variables declaration 

} 
+0

慌てて、ダイアログの表示後に実行されたプログラムの残りの部分をコメントアウトして正しく機能しました。それが起こる理由は何ですか? – Max

+0

私の頭に浮かぶ最初のアイデアは、あなたが何らかの形で「コンテンツ」または「ウィンドウ」オブジェクトを使用していることです。 – shybovycha

関連する問題