wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Help Menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help Menu" Watch "Help Menu" New topic
Author

Help Menu

Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
I am writting an application, that has a help menu on the menu bar. I would like to write the menu pages in html and display them in a JTextArea.
Is it a) possible to show previously formatted text in a JTextArea ?
b) best to write the html pages externally or to write the html in as a constant string and keep this as a compiled class in a utility package?
Ivor Horton
Author
Ranch Hand

Joined: Mar 22, 2002
Posts: 67
You might find it easier to use a JEditorPane object to hold the help text as this has a built-in capability to display text fromatted with html.
For small amounts of help text, keeping it within the program code is fine, but for significant quantities you would be better off using an external file to store the text and fetching it as required. You might pre-fetch part of it at start-up if you can identify the bits most likely to be required. An external file would also provide an open-ended capacity for help and would be easier to edit and update that messing with the source code each time you want to change the help data.


Ivor Horton<br />Author of the Beginning Java Series including the new <a href="http://www.amazon.com/exec/obidos/ASIN/1861005695/ref=ase_electricporkchop" target="_blank" rel="nofollow">Beginning Java 2 SDK 1.4 Edition</a>
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Ivor thanks for your reply. For testing purposes I have created an inner class as follows.
the variable content in the line content.add(scrollPane); is a variable from my outer class created using Container content = fame.getContentPane();

This code compiles fine but when I test the functionality I get the previous frames components spread out on a larger frame. I hope you can point me in the right direction as I don't know where I am going wrong.
[ March 26, 2002: Message edited by: Nigel Browne ]
Ivor Horton
Author
Ranch Hand

Joined: Mar 22, 2002
Posts: 67
From what you say I guess your content pane has other components added to it. If you want to replace the content pane that has the other components, you could create a JPanel and add your JScrollPane to that. Then call setContentPane() for the JFrame object to make the panel containing the scroillpane the new content pane. If you have saved to old content pane (as your variable content), you can always put it back when you are done with the help pane.
btw. You can use the setPage() method for a JEditorPane object to load data from a URL (that can of course refer to a local file).
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Thanks for your replys. When you were talking about saving the variable content and then returning to it at a later stage. Is it possible from a hyperlink to call a method that accomplishes this ?
Ivor Horton
Author
Ranch Hand

Joined: Mar 22, 2002
Posts: 67
If you have stored a reference to the content pane for your JFrame object in the variable content, as in:
Container content = frame.getContentPane();
You might then add all kinds of stuff to this content pane. When you want to display your help info, you can replace the content pane with the statement:
frame.setContentPane(scrollPane); // insert help pane
Later you can restore it along with everything it contains with the statement:
frame.setContentPane(content);
 
wood burning stoves
 
subject: Help Menu
 
Similar Threads
Saving JTextArea's Content
How to use menu items
HTML Include
writing help file - please help
readme and package questions