Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...

Swing Chapter 25. (Special topics) JavaHelp. Easy for reading, Click here!

Custom Search
Swing Chapter 25. (Special topics) JavaHelp. Easy for reading, Click here!

[ Return to Swing (Book) ]

Page: 2/6 

Previous Page Previous Page (1/6) - Next Page (3/6) Next Page
Subpages: 1. JavaHelp introduction
2. JavaHelp API overview
3. Basic JavaHelp example
4. Adding dialog-style help
5. Customizing the JHelp viewer
5. Creating a custom help view

25.2  JavaHelp API overview

25.2.1  HelpSet

class javax.help.HelpSet

This class represents a collection of help information files we discussed above: HelpSet, table of contents (TOC), index, content, and map files. To create a HelpSet instance we must supply two parameters: a ClassLoader instance used to locate any classes required by the navigators in the help set, and the URL of the main HelpSet file. The following code shows a typical HelpSet instantiation, assuming the main HelpSet file, MyHelpSet.hs, is contained in the current running directory:

    ClassLoader loader = this.getClass().getClassLoader();

    URL url = HelpSet.findHelpSet(loader, "MyHelpSet.hs");

    HelpSet hs = new HelpSet(loader, url);

25.2.2  The HelpBroker interface

abstract interface javax.help.HelpBroker

This interface describes a component used to manage the presentation and interaction with a HelpSet. We can use the HelpSet.createHelpBroker() method to retrieve an instance of HelpBroker. We can then use HelpBroker's enableHelpKey() method, specifying the String ID of a desired help topic, to enable JavaHelp on a given Component. This is often used on a JRootPane (see chapter 3):

    HelpBroker hb = hs.createHelpBroker();

    hb.enableHelpKey(myFrame.getRootPane(), "MyTopicID", hs);

When F1 is pressed while that component, or one of its children, has the focus, the JavaHelp viewer will appear displaying the appropriate help topic. If a child component has the focus and has an associated help ID assigned, the help viewer will display the help topic specific to that component. Otherwise the default topic (specified as "MyTopicID" above) will be displayed.

We can also use the enableHelpOnButton() method to enable the display of JavaHelp when a specific button is pressed:

    JButton btHelp = new JButton("Help");

    hb.enableHelpOnButton(btHelp, "MyTopicID", null);

A default implementation is provided by the javax.help.DefaultHelpBroker class.

25.2.3  The Map interface

abstract interface javax.help.Map

This interface defines a String ID to URL mapping. The inner class Map.ID is used to identify a help topic. It encapsulates a HelpSet reference / String ID pair. Given an ID we can get the associated URL and vice versa. Each HelpSet has an associated Map instance.

25.2.4  JHelp

class javax.help.JHelp

This class represents the main JavaHelp viewer capable of displaying help set data using JTree or JList navigators in a JTabbedPane, and a content viewer (normally a JEditorPane for HTML display). The current implementation of JavaHelp does not provide public access to this class via HelpSet or HelpBroker instances. Later in this chapter we'll see how to gain access to this component for customization.

25.2.5  The HelpModel interface

abstract interface javax.help.HelpModel

This interface represents the model of a JHelp viewer component. It maintains IDs and URLs corresponding to the HelpSet being displayed in a JHelp instance, and fires HelpModelEvents (see below) when the current help topic is changed.

25.2.6  JHelpNavigator

class javax.help.JHelpNavigator

This class represents a navigation control (JTree or JList) for the GUI presentation of help topic data. Instances of JHelpNavigator reside in the tabbed pane on the left side of the JHelp viewer. Any number of navigators can be present in a HelpSet. JavaHelp provides three sub-classes of JHelpNavigator used in JHelp by default: JHelpIndexNavigator, JHelpSearchNavigator, and JHelpTOCNavigator. Each JHelpNavigator displays data retrieved through a specific NavigatorView instance.

25.2.7  NavigatorView

abstract class javax.help.NavigatorView

Instances of NaviagtorView define what type of data a view accepts and how it is parsed. They aso define how data will be presented visually by specifying a corresponding component used to view it. JavaHelp provides three sub-classes of NavigatorView used in JHelp by default: IndexView, SeachView, and TOCView--each of which specify the corresponding JHelpNavigator subclass discussed above for representation.

25.2.8  CSH

class javax.help.CSH

This class provides simple access to context-sensitive help by supplying several static methods. Context-sensitive help is the provision of certain help information based on the user's current task. Implementing this type of help often involves associating help topics with each component in a GUI and tracking context-sensitive events. Particularly important is the CSH.setHelpIDString(JComponent comp, String helpID) method, which assigns a String ID to a given Swing component. When all IDs are assigned, we can create a button or menu item to trigger content sensitive help, and attach a special predefined ActionListener:

    JButton btItemHelp = new JButton("Item Help");

    btItemHelp.addActionListener(new CSH.DisplayHelpAfterTracking(hb));

When this button is pressed, a custom mouse cursor displaying a pointer and a question mark appears. When a component is clicked the JavaHelp viewer is displayed showing the help topic corresponding to the selected component's assigned ID (if it has one).

25.2.9  TreeItem

class javax.help.TreeItem

Instances of this class are used as user objects in a navigational view's JTree or JList. Subclasses of TreeItem include IndexItem, used in the Index navigator, and TOCItem, used in the TOC navigator. A SearchTOCItem class extends TOCItem and is used in the Search navigator.

25.2.9  The HelpModelListener interface

abstract interface javax.help.event.HelpModelListener

This interface describes a listener which receives javax.help.event.HelpModelEvents when the current help topic is changed (i.e. whenever a new topic is selected in a navigator). HelpModelListener implementations must implement the idChanged() method which takes a HelpModelEvent as parameter. We can add a HelpModelListeners to a HelpModel using its addHelpModelListener() method.

25.2.10            Setting up JavaHelp

To run all examples in this chapter you will need to do the following (this will vary depending on your platform):

1. Download and install JavaHelp 1.0 (or the most recent release).

2. Copy all files in your javahelp\bin directory to your jdk1.2\bin directory.

3. Copy the contents of your javahelp\lib directory to your jdk1.2\lib directory.

4. Each example includes Windows batch files set up with the assumption that you have installed Java 2, and the above files, in c:\jdk1.2. If you are not using Windows or do not have Java 2 installed in this directory, you will need to write your own scripts or modify these batch files accordingly.

Note: The JavaHelp API now exists as a Java extension. In future Java 2 releases it is possible that JavaHelp will become part of the core API.

[ Return to Swing (Book) ]

Top 10 read Java Articles
 Get free "1000 Java Tips eBook"

 Java Calendar and Date: good to know facts and code examples

 Array vs ArrayList vs LinkedList vs Vector: an excellent overview and examples

 How can I convert any Java Object into byte array? And byte array to file object

 The Java Lesson 1: What is Java?

 How do I compare two dates and times, date between dates, time between times and

 Maven vs Ant or Ant vs Maven?

 How to open, read, write, close file(s) in Java? Examples on move, rename and de

 Java Array

 Java: JLabel font and color

[ More in News Section ]
Java Lessons

The Java Lesson 1:
What is Java?
The Java Lesson 2:
Anatomy of a simple Java program
The Java Lesson 3:
Identifiers and primitive data types
The Java Lesson 4:
Variables, constants, and literals
The Java Lesson 5:
Arithmetic operations, conversions, and casts
The Java Lesson 6:
Boolean expressions and operations
The Java Lesson 7:
Bitwise operations
The Java Lesson 8:
Flow control with if and else
The Java Lesson 9:
switch statements
The Java Lesson 10:
for, while, and do-while statements
The Java Lesson 11:
Using break and continue
The Java Lesson 12:
Class methods and how they are called
The Java Lesson 13:
Using the Math class
The Java Lesson 14:
Creating and calling custom class methods
The Java Lesson 15:
Overloading class methods
The Java Lesson 16:
An introduction to objects and object references
The Java Lesson 17:
The String class
The Java Lesson 18:
The StringBuffer class
The Java Lesson 19:
Initializing and processing arrays of primitives
The Java Lesson 20:
Initializing and processing arrays of objects
The Java Lesson 23:
Inheritance and overriding inherited methods
The Java Lesson 24:
abstract classes and polymorphism
The Java Lesson 25:
Interfaces, instanceof, and object conversion and casting
The Java Lesson 26:
Introduction to graphical programming and the java.awt packa
The Java Lesson 27:
The Component class
The Java Lesson 28:
Containers and simple layout managers
The Java Lesson 29:
The Color and Font classes
The Java Lesson 30:
Drawing geometric shapes
The Java Lesson 31:
Choice, List, and Checkbox controls
The Java Lesson 32:
Using the Scrollbar graphical control
The Java Lesson 33:
Menus and submenus
The Java Lesson 34:
An introduction to applets and the Applet class
The Java Lesson 35:
Essential HTML to launch an applet and pass it parameters
The Java Lesson 36:
Mouse event processing
Java Lesson 37:
Menus and submenus
Java Lesson 38:
The WindowListener interface and the WindowAdapter class
Java Lesson 39:
An introduction to GridBagLayout
Java Lesson 40:
An introduction to the Java Collections API
Java Lesson 41:
Exception handling with try, catch, and finally blocks
Java Lesson 42:
Claiming and throwing exceptions
Java Lesson 43:
Multithreading, the Thread class, and the Runnable interface
Java Lesson 44:
An introduction to I/O and the File and FileDialog classes
Java Lesson 45:
Low-level and high-level stream classes
Java Lesson 46:
Using the RandomAccessFile class
Java Lessons by
Joh Huhtala: Update

Latest articles
 Java Profiler JProbe to Resolve Performance Problems Faster

 SSL with GlassFish v2, page 5

 SSL with GlassFish v2, page 4

 SSL with GlassFish v2, page 3

 SSL with GlassFish v2, page 2

 The Java Lesson 2: Anatomy of a simple Java program, page 2

 New site about Java for robots and robotics: both software and hardware.

 Exceptions -III: What's an exception and why do I care?

 Exceptions -II: What's an exception and why do I care?

 Exceptions: What's an exception and why do I care?

 Double your Java code quality in 10 minutes, here is receipt

 Murach's Java Servlets and JSP

 How to get ascii code from a char in Java?

 Can we just try without catch? Yes!

 Make Tomcat page load faster

 Make your Tomcat More secure - limit network address for certain IP addresses

 New Java book online starts now here...

 Implementing RESTful Web Services in Java

 Firefox trimming from 1 GB to 40 Mb with many tabs opened

 SSL with GlassFish v2

 My request to replublish Tech Tips

 Search JavaFAQ.nu site here

 New Advanced Installer for Java 6.0 brings XML updates and imports 3rd party MSI

 EJB programming restrictions

 Maven vs Ant or Ant vs Maven?

 Why Java does not use default value which it should?

 How to unsign signed bytes in Java - your guide is here

 The Java Lesson 3: Identifiers and primitive data types. Page 2

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 4

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 3

[ More in News Section ]

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy