help - accidentally creating floating applet
Ben.Manes_at_gmail.com
Date: 01/07/05
- Next message: Rohan Chaudhari via JavaKB.com: "Problem with JTable in a JScrollPane"
- Previous message: Chris Uppal: "Re: Making Java Programs Pluggable??"
- Next in thread: Andrew Thompson: "Re: help - accidentally creating floating applet"
- Reply: Andrew Thompson: "Re: help - accidentally creating floating applet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Jan 2005 02:00:01 -0800
Hi,
I'm porting jEdit's help system into an applet form. Its complete,
except for an annoyance - it loads as a seperate window, leaving a dead
HTML page behind. I'd like to instead embed the applet inside the HTML
page, so I can have a link create a popup window. As it is now, if you
close the HTML page it closes the applet.
I used the generic jBuilder code to create the applet, and added this
like to start()
HelpViewer frame = new HelpViewer();
The GUI is created using in the HelpViewer's constructor (HelpViewer
extends JFrame):
/** HelpViewer
* Creates a new HelpViewer for specified URL
* @param URL
*/
public HelpViewer(String url)
{
this.setTitle("Insight Help");
utilities = MiscUtilities.getInstance();
// Chack if valid URL
try
{
// Check if protocal included
new URL(url).getProtocol();
// Valid protocol, so if pointing to specific HTML file, remove
Log.log(Log.ERROR, this, "Parse URL for hostname");
}
catch (MalformedURLException e)
{
// No protocol - therefore assume local
if (e.getMessage().startsWith("no protocol"))
baseURL = utilities.getRemoteURL() + "/docs/";
else
{
Log.log(Log.ERROR, this, e.getMessage());
//Set to error page?
}
}
// Create history
history = new String[25];
ActionHandler actionListener = new ActionHandler();
// Setup tabs
JTabbedPane tabs = new JTabbedPane();
tabs.addTab("Contents", toc = new HelpTOCPanel(this));
tabs.addTab("Search", new HelpSearchPanel(this));
tabs.addTab("Glossary", new HelpGlossary(this));
tabs.setMinimumSize(new Dimension(0,0));
// Setup toolbar
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(false);
toolBar.add(title = new JLabel()); // title of current page
toolBar.add(Box.createGlue());
JPanel buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS));
buttons.setBorder(new EmptyBorder(0,12,0,0));
// Add back button
back = new JButton(utilities.loadIcon("ArrowL.png"));
back.setToolTipText("Back");
back.addActionListener(actionListener);
toolBar.add(back);
// Add forward button
forward = new JButton(utilities.loadIcon("ArrowR.png"));
forward.setToolTipText("Forward");
forward.addActionListener(actionListener);
toolBar.add(forward);
back.setPreferredSize(forward.getPreferredSize());
// Add home button
home = new JButton(utilities.loadIcon("Home.png"));
home.setToolTipText("Home");
home.addActionListener(actionListener);
toolBar.add(home);
// Add toolbar to panel
JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.add(BorderLayout.NORTH,toolBar);
// Setup Viewer Panel
viewer = new JEditorPane();
viewer.setEditable(false);
viewer.addHyperlinkListener(new LinkHandler());
viewer.setFont(new Font("Monospaced",Font.PLAIN,12));
viewer.addPropertyChangeListener(new PropertyChangeHandler());
rightPanel.add(BorderLayout.CENTER,new JScrollPane(viewer));
// Split Pane
splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tabs,
rightPanel);
splitter.setBorder(null);
getContentPane().add(BorderLayout.CENTER,splitter);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
getRootPane().setPreferredSize(new Dimension(750,500));
pack(); // causes window to fit the preferred size
setVisible(true);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
splitter.setDividerLocation(250);
viewer.requestFocus();
}
});
gotoURL(url,true);
}
Any advice would be appreciated!
-Ben
- Next message: Rohan Chaudhari via JavaKB.com: "Problem with JTable in a JScrollPane"
- Previous message: Chris Uppal: "Re: Making Java Programs Pluggable??"
- Next in thread: Andrew Thompson: "Re: help - accidentally creating floating applet"
- Reply: Andrew Thompson: "Re: help - accidentally creating floating applet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]