Page 1 of 1

mising toolbar icon

Posted: Tue Jun 30, 2015 11:11 pm
by sderrick
I added the "Edit/Toggle_line_wrap" action to the toolbar in the sdk applet

The icon is missing.

How can I add that?

thanks,

Scott

Re: mising toolbar icon

Posted: Wed Jul 01, 2015 8:24 am
by Radu
Hi Scott,

We just don't provide an icon for this specific action (because we never intended it to be added to a toolbar).

But you can create (or copy from some place) your own icon for it and set it to the action before creating a toolbar button from it:

Code: Select all

((javax.swing.AbstractAction)action).putValue(Action.SMALL_ICON, yourCustomIcon);
Or create your own Swing action with your own properties which delegates to our action when actionPerformed is called on it.

Regards,
Radu

Re: mising toolbar icon

Posted: Fri Apr 13, 2018 6:45 am
by RBVanDyke
Can someone please point we less sophisticated users to the information needed to "create (or copy from some place) your own icon for it and set it to the action"?

Thanks,
Riley
SFO

Re: mising toolbar icon

Posted: Fri Apr 13, 2018 8:32 am
by Radu
Hi Riley,

Let's say that in your Java project you create in your "src" folder an "images" subfolder containing all custom images like for example an image called "OpenCustom.png".
The JAR library which will be created from your Java sources will contain inside this "images" subfolder with the images.
In your Java code you can create an ImageIcon from your image:

Code: Select all

	private ImageIcon createOpenIcon() {
ImageIcon icon = null;
InputStream is = AuthorComponentSample.class
.getResourceAsStream("/images/OpenCustom.png");
try {
icon = new ImageIcon(ImageIO.read(is));
} catch (IOException e) {
}
return icon;
}
Once you have the ImageIcon you can use it on an action like:

Code: Select all

				AbstractAction openAction = new AbstractAction("Open",
createOpenIcon()) {
public void actionPerformed(ActionEvent e) {
// Open the file
openFile();
}
};
actionsToolbar.add(new ToolbarButton(openAction, false));
Regards,
Radu