子窗体上如何弹出自定义对话框

steven138 2007-11-27 04:42:34
MyFrm extends JInternalFrame
MyDialog extends JDialog
MyDialog的构造函数中要指明owner,但只能是Frame或Dialog类的
我想问问怎么在MyFrm上弹出MyDialog
...全文
202 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jaguarlsl 2007-11-29
  • 打赏
  • 举报
回复
要想使用JOptionPane必须自己的窗体继承自JFrame或者JDialog,如果是JInternalFrame,你可以在弹出时以JInternalFrame的父窗体为参数弹出JOptionPane
ehack 2007-11-28
  • 打赏
  • 举报
回复
路过,来看看
你怎么 extends JPanel?
qybao 2007-11-27
  • 打赏
  • 举报
回复
MyFrm extends JInternalFrame
MyDialog extends JDialog
MyDialog的构造函数中要指明owner,但只能是Frame或Dialog类的
我想问问怎么在MyFrm上弹出MyDialog
-------------------------------
MyDialog的owner参数可以传一个null

steven138 2007-11-27
  • 打赏
  • 举报
回复
照楼上的改成这样了
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,请问怎么修改
chenweionline 2007-11-27
  • 打赏
  • 举报
回复
Object message 参数可以是任意对象,你可以将你自定义的jpanel做为参数传入。
steven138 2007-11-27
  • 打赏
  • 举报
回复
忘记说了我的MyDialog是自定义的,楼上的不行
lihaifeng0412 2007-11-27
  • 打赏
  • 举报
回复
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 参数确定。
chenweionline 2007-11-27
  • 打赏
  • 举报
回复
在 JInternalFrame 上可以用 JOptionPane 构造对话框

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧