简体   繁体   English

带有自定义按钮的JOptionPane showInputDialog

[英]JOptionPane showInputDialog with custom buttons

我可以在自定义按钮上使用showInputDialog,还是可以在showInputDialog上重命名“ OK”和“ Cancel”按钮。

There are a bunch of variants of each JOptionPane method. 每个JOptionPane方法都有很多变体。 And choosing the one will usually give you access to the desired level of feature. 选择一个通常可以使您访问所需的功能级别。 In your case, you're looking for 就您而言,您正在寻找

public static Object showInputDialog(Component parentComponent,
                                 Object message,
                                 String title,
                                 int messageType,
                                 Icon icon,
                                 Object[] selectionValues,
                                 Object initialSelectionValue)

See its javadoc here: JOptionPane#showInputDialog . 在此处查看其javadoc: JOptionPane#showInputDialog notice you won't change here the buttons colors (as they're look-and-feel dependant) but rather change their text (which is generally speaking enough, as you can also here set the icon displayed on dialog left side). 请注意,您不会在这里更改按钮的颜色(因为它们取决于外观),而是更改其文本(通常来说已经足够,因为您也可以在此处设置对话框左侧显示的图标)。

Check out the JOptionPane documentation . 查阅JOptionPane文档


You can send an array of objects that define the buttons: 您可以发送定义按钮的对象数组:

Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue': 显示一个警告对话框,其中包含“确定”,“取消”,标题“警告”和消息“单击确定以继续”的选项:

Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);

为什么不创建自己的JDialog派生类?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM