This is a modifed version of SwingTester that can be called from a separate program.
The app can be called from a JMenuItem action listener as follows.
viewItem.addActionListener(actionEvent -> { ViewApp.createWindow("help.html"); })
ViewApp.java
import java.awt.*; import java.awt.Dimension; import java.io.IOException; import java.net.URL; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; public class ViewApp { static JFrame frame; public static void main(String[] args) { String filename = args.length>0? args[0]: "help.html"; createWindow(filename); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void createWindow(String filename) { frame = new JFrame("View Help"); createUI(filename); frame.setSize(560, 450); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); } private static void createUI(String filename){ JEditorPane area = new JEditorPane(); area.setEditable(false); URL url= ViewApp.class.getResource(filename); try { area.setPage(url); } catch (IOException e) { area.setContentType("text/html"); area.setText("<html>Page not found.</html>"); } JScrollPane spanel = new JScrollPane(area); spanel.setPreferredSize(new Dimension(540,400)); frame.add(spanel); } }
Maintained by John Loomis, updated Sat Apr 25 09:20:17 2020