现在位置和大小并不重要,我所需要的是在对话框中设置一个自定义图像图标,而不是默认的java图标。
以下是我到目前为止所做的工作:
public void actionPerformed(ActionEvent a) {
int x=0;
// Import Asus logo
ImageIcon img3 = new ImageIcon("AsusConfirmation.jpeg");
// Create user-friendly information message
int c = JOptionPane.showConfirmDialog(null, "Your grand total is $"+x+"!\nIs this order correct?", "Checkout", JOptionPane.YES_NO_OPTION, img3);
if(c==JOptionPane.YES_OPTION) {
System.exit(0);
}
}我在这段代码中得到的错误是,我不能将Image转换为int,并且删除了int部分,然后我将无法使用:
if(c==JOptionPane.YES_OPTION) {
System.exit(0);
}发布于 2016-05-24 06:05:51
您使用的方法签名不正确。请参阅Javadoc
public static int showConfirmDialog(Component parentComponent,
Object message,
String title,
int optionType,
-> int messageType, <-
Icon icon)
throws HeadlessException您正在做的是落入另一个不同的签名中,该签名不提供Icon
public static int showConfirmDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType)
throws HeadlessException但是没有给出int,导致编译器抱怨类型不匹配。
您必须做的是,添加缺少的messageType参数,然后您将匹配第一个方法签名。
https://stackoverflow.com/questions/37401159
复制相似问题