我有以下代码:
principleInputString = JOptionPane.showInputDialog(null,"Enter the principle.","Find Interest Rate", JOptionPane.PLAIN_MESSAGE);
我想在JOptionPane中显示一个图标以及我的消息。我怎么做? 我这样做时收到错误消息:
final ImageIcon icon = new ImageIcon(new URL("http://iconizer.net/files/Devine_icons/thumb/128/Calculater.png"));
principleInputString = JOptionPane.showInputDialog(null,"Enter the principle.","Find Interest Rate", JOptionPane.PLAIN_MESSAGE,icon);
答案 0 :(得分:2)
要将图像添加到JOptionPane
,我相信这就是您的目标
import javax.swing.*;
import java.awt.*;
public class Test
{
public static void main(String[] args)
{
final ImageIcon icon = new ImageIcon("yourimage.imagetype");
Image image2 = icon.getImage().getScaledInstance(200,200,0);
String principleInputString = JOptionPane.showInputDialog(null,"Enter the principle.","Find Interest Rate", JOptionPane.PLAIN_MESSAGE, new ImageIcon(image2), null, "").toString();
}
}
有关详细信息,请查看here