hcl-bot
1
Hi
I’m using Swing to provide an user interface in an local scheduled agent.
This works great but i would like to use an image from the filesystem …(or if possible from an image ressource from the Notes database) in a button.
I’m using ImageIcon
ImageIcon icon = new ImageIcon(“domino/icons/actn010.gif”);
I have tried different setups. relative file paths, absolute path, URLs…
I can not get to work. Any ideas?
Is is Java security restrictions?
regards
Jesper Kiaer
http://www.jezzper.com
Subject: ImageIcon (Swing) in an agent
Hi,
I had the same problem and I found a solution:
Write a java-function like this:
private ImageIcon getImageIcon(String sImagePath)
{
ImageIcon newIcon = null;
try
{
InputStream isImage = DlgSearchDeZent.class.getResourceAsStream(sImagePath);
byte[] buf = new byte[isImage.available() ];
isImage.read(buf);
newIcon = new ImageIcon(buf);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, "Image '" + sImagePath + "' could not be loaded.", "Error", JOptionPane.ERROR_MESSAGE);
}
return newIcon;
}
The images must be a part of your java-project.