MyFrm extends JInternalFrame
MyDialog extends JDialog
MyDialog的构造函数中要指明owner,但只能是Frame或Dialog类的
我想问问怎么在MyFrm上弹出MyDialog

解决方案 »

  1.   

    在 JInternalFrame 上可以用 JOptionPane 构造对话框
      

  2.   

    static int showInternalConfirmDialog(Component parentComponent, Object message) 
              调出带有选项 Yes、No 和 Cancel 的内部对话框面板;标题为 Select an Option。 
    static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType) 
              调出一个由 optionType 参数确定其中选项数的内部对话框面板。 
    static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) 
              调出一个由 optionType 参数确定其中选项数的内部对话框面板,messageType 参数确定要显示的图标。 
    static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) 
              调出一个带有指定图标的内部对话框面板,其中的选项数由 optionType 参数确定。 
    static String showInternalInputDialog(Component parentComponent, Object message) 
              显示请求用户输入内容的内部问题消息对话框,它以 parentComponent 为父级。 
    static String showInternalInputDialog(Component parentComponent, Object message, String title, int messageType) 
              显示请求用户提供输入的内部对话框,该对话框的标题为 title,消息类型为 messageType,并以 parentComponent 为父级。 
    static Object showInternalInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) 
              提示用户在可以指定初始选择、可能选择及其他所有选项的模块化的内部对话框中输入内容。 
    static void showInternalMessageDialog(Component parentComponent, Object message) 
              调出内部确认对话框面板。 
    static void showInternalMessageDialog(Component parentComponent, Object message, String title, int messageType) 
              调出一个显示消息的内部对话框面板,它使用由 messageType 参数确定的默认图标。 
    static void showInternalMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon) 
              调出一个显示消息的内部对话框面板,为其指定了所有参数。 
    static int showInternalOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) 
              调出一个带有指定图标的内部对话框面板,其中的初始选择由 initialValue 参数确定,选项数由 optionType 参数确定。 
      

  3.   

    忘记说了我的MyDialog是自定义的,楼上的不行
      

  4.   

    Object message 参数可以是任意对象,你可以将你自定义的jpanel做为参数传入。
      

  5.   

    照楼上的改成这样了
    class MyPanel extends JPanel{
    JLabel l1=new JLabel("xxxxxxxxxx");
    JLabel l2=new JLabel("xxxxxxxxxx");
    JTextField t1=new JTextField(10);
    JTextField t2=new JTextField(10);
    public AddStudent(){
    //super(parent,modal);
    this.setLayout(null);
    l1.setBounds(30,30,115,20);
    l2.setBounds(30,60,115,20);
    t1.setBounds(150,30,120,20);
    t2.setBounds(150,60,120,20);
    add(l1);add(l2);add(t1);add(t2);
    this.setSize(200,170);
    //this.setResizable(false);
    }
    }
    class MyFrm extends JInternalFrame implements ActionListener{
         public void actionPerformed(ActionEvent e){
    if(e.getSource()==b2){
         String[] bt={"确定","取消"};
         JOptionPane.showOptionDialog(this,new MyPanel(),"",JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,bt,true);
            }
         }
    }
    但弹出的对话框只有2个btn,请问怎么修改
      

  6.   

    MyFrm   extends   JInternalFrame 
    MyDialog   extends   JDialog 
    MyDialog的构造函数中要指明owner,但只能是Frame或Dialog类的 
    我想问问怎么在MyFrm上弹出MyDialog
    -------------------------------
    MyDialog的owner参数可以传一个null
      

  7.   

    路过,来看看 
       你怎么 extends JPanel?
      

  8.   

    要想使用JOptionPane必须自己的窗体继承自JFrame或者JDialog,如果是JInternalFrame,你可以在弹出时以JInternalFrame的父窗体为参数弹出JOptionPane