为什么弹出的frame 没有呎寸..?
什么原因?import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class t2 extends JPanel {
  
  JButton button ;
 
  public t2() {
    button = new JButton("Open");
    setLayout(new FlowLayout());
    add(button);
 
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        dialog dlog = new dialog(new Frame(), true);  
      }
    });
  }
  
  private static void createAndShowGUI() {
        
        JFrame frame = new JFrame("TimeTabling System");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        JComponent newContentPane = new t2();
        newContentPane.setOpaque(true); 
        frame.setContentPane(newContentPane);
 
        frame.pack();
        frame.setVisible(true);
    }
 
    public static void main(String[] args) {
        
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
 
class dialog extends JDialog{
 
  JButton OKBtn, CancelBtn;
 
  public dialog(Frame parent, boolean modal){
    super(parent, modal);
    setLayout(new FlowLayout());
    OKBtn =  new JButton("OK"); 
    CancelBtn =  new JButton("CancelBtn"); 
    add(OKBtn);
    add(CancelBtn);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setVisible(true);
    pack();
    
  }
 
}

解决方案 »

  1.   

    dialog构造方法中在setVisible句前加setSize句
    默认是0 
      

  2.   

    为什么没有跟着 main frame 弹出???dialog dlog = new dialog(new Frame(), true);
    dlog .addSendObjectListen(this);
      

  3.   

    为什么没有跟着 main frame 弹出??? dialog dlog = new dialog(new Frame(), true);
    dlog.setLocationRelativeTo(this);