Reputation: 7603
How can I set the JFrame Icon
(top left of the outer JFrame
) of the JavaHelp Window
. I know how to set the category and topic Images
(toc.xml), but I don't succceed in setting the JFrame Icon
.
I could do it programmatically, by looking for the frame and setting the icon, but I am looking for a way to do this declaratively using the JavaHelp configuration files.
Upvotes: 1
Views: 832
Reputation: 1251
Create a class called Help and a public/protected method called setIconImage(String IconPath) that accepts a string parameter inside your class (Help).
Note: Your Help class is the one where you call (initialize) your JavaHelp API.
Inside your setIconImage() method copy and paste the following code:
frame.setIconImage(new ImageIcon(getClass().getResource(imagePath)).getImage());
I.e.
public void setIconImage(String imagePath)
{
frame.setIconImage(new ImageIcon(getClass().getResource(imagePath)).getImage());
}
Now you can call your Help class from another class.
Example
Calling class:
Help help = new Help();
help.setIconImage("/path_to_your_icon_image/myHelpFrameIcon_45x45.png");
Help class:
public class Help{
JHelp helpViewer = null;
JFrame frame;
public Help(){
try
{
ClassLoader cl = Help.class.getClassLoader();
URL url = HelpSet.findHelpSet(cl, "jhelpset.hs");
helpViewer = new JHelp(new HelpSet(cl, url));
helpViewer.setCurrentID("Simple.Introduction");
} catch (Exception e)
{
System.err.println("API Help Set not found");
}
frame = new JFrame();
frame.setSize(800,700);
frame.getContentPane().add(helpViewer);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
public void setIconImage(String imagePath){
frame.setIconImage(new ImageIcon(getClass().getResource(imagePath)).getImage());
}
public static void main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run()
{
new Help();
}
});
}
}
Finish! Have fun :)
Upvotes: 0
Reputation: 7603
The most answers on google are plain wrong. In most examples of the helpset xml the order of the tags is wrong, if you compare it with the dtd you will notice that the element has to come at the end of the element and not at the beginning as most examples do. Steps 2 and 3 are well known, it is step 1 that is not visible anywhere.
To recap: the solution is to (1) put the <presentation>
element in the correct location, (2) add an <image>
element and (3) declare it in the map file as wel.
Memes on the internet that don't work:
Upvotes: 1