JFrame
. We will have the following structure: public class BasicXULSample extends JFrame { public BasicXULSample(File file) { super("XUL SampleChoice"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); init(file); } private void init(File file) { // do all the javaXUL stuff here } public static final void main(String[] args) { // select the file BasicXULSample sample = new BasicXULSample(<the file>); sample.setVisible(true); } }
public class BasicXULSample extends JFrame { public BasicXULSample(File file) { super("XUL SampleChoice"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); init(file); } private void init(File file) { // do all the javaXUL stuff here } public static final void main(String[] args) { JFileChooser chooser = new JFileChooser("Select XUL file"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); int ret = chooser.showOpenDialog(null); if (ret == JFileChooser.OPEN_DIALOG) { BasicXULSample sample = new BasicXULSample(chooser.getSelectedFile()); sample.setVisible(true); } } }
ScriptManager
JFrame
, and ensure that the toobar and menubar are also added to the JFrameprivate void init(File file) { DefaultScriptManager manager = new DefaultScriptManager(); manager.addXULScript(file); manager.install(this); manager.setActive(true); }This is done. Now let's start our application and open a XUL script (you can use one of the examples in the
samples
directory). You should have the following result:manager.install(this);by:
// the boolean value is set to true to specify that we want to put the content in a scroll pane manager.install(this, true);Now we have the following result:
print
message in a integrated logger rather than on the System default output stream. We can perform: private void init(File file) { DefaultScriptManager manager = new DefaultScriptManager(); manager.validateXULSchema(true); manager.setParserErrorReporter(new SwingParserErrorReporter()); // we specify that we wil use a Swing exception listener to catch exceptions and show them in a specific error window manager.setScriptExceptionListener(new SwingExceptionListener()); // we specify the script logger as the default script logger. manager.setScriptLogger(new DefaultSwingScriptLogger()); manager.addXULScript(file); // the first boolean value is set to true to specify that we want to put the content in a scroll pane // the second boolean value is set to true to specify that we want to add a log area at the bottom of the window // the last int value defines the number of lines of the logger manager.install(this, true, true, 10); this.pack(); manager.setActive(true); }Now we have the following result:
Copyright 2008-2020 Herve Girod. All Rights Reserved. Documentation and source under the LGPL licence