{{htmlmetatags>
metatag-keywords=(mathtype, google docs, office, math editor, equation, wiris, math, maths, lms, pages, documentation, user-guide, handwritten input)
metatag-description=(Learn how to use Mathtype Web to create math and chemistry notation for Google Docs or your favorite LMS or web application.)
}}
====== Java Swing ======
[MW] for Java Swing is the specialized compilation of [MW] that targets Java Swing. With this Java component, you can add to your application a full-fledged formula (equation) editor for maths, physics and (inorganic) chemistry that works with the MathML standard. The usage is very similar to the JavaScript version.
Contact [[sales@wiris.com|our sales team]] if you want to know more or you are interested in purchasing this product.
===== Overview =====
[MW] for Java Swing comes also with an API that converts from/to LaTeX, generates images of the formulas in different formats (PNG, SVG) and is able to generate the textual representation of a formula used in accessibility. See [[en:mathtype:mathtype_web:sdk-api:services|editor services]] and [[https://www.wiris.net/demo/editor/docs/library-api/|library api]].
Follow the instructions below to embed the [MW] in a Java Swing application.
The actual look & feel is inherited from your swing application.
The integration is made in two steps. The first step displays the editor itself and the second step calls the editor API to set and retrieve the MathML.
===== MathType as a modal dialog =====
The easiest way to integrate [MW] is by displaying it as a modal window, outside the main application window.
[MW] provides a method to open a dialog and retrieve the submitted MathML in an easy and fast way:
String mathml = JavaEditorDialog.showDialog(window);
if (mathml != null) {
System.out.println("MathML: " + mathml);
}
else {
System.out.println("Operation cancelled by the user");
}
This way also allows the inclusion of parameters:
Properties p = new Properties();
p.setProperty("language", "en");
String mathml = JavaEditorDialog.showDialog(window, p);
===== MatType Web as plain component =====
You can create a new Java Swing application and add the following main class:
package com.wiris.javaEditor;
import java.util.Properties;
import javax.swing.JFrame;
public class JavaEmbeddedExample {
public static void main(String[] args) {
Properties p = new Properties();
p.setProperty("language", "en");
JavaEditor editor = new JavaEditor(p);
JFrame window = new JFrame();
window.add(editor);
window.pack();
window.setVisible(true);
System.out.println(editor.getMathML());
editor.setMathML("");
}
}
In the above code, the variable editor will be used later to access the API.
Calling the editor API to get the MathML:
System.out.println(editor.getMathML());
To set the MathML:
editor.setMathML("");
===== Initialization parameters =====
See the full table of the initialization parameters. Choosing the language
In the previous example, we passed the following parameter
p.setProperty("language", "en");
which specifies to use English for the text in the user interface. Changing the toolbar
The parameter 'toolbar' can be used to specify the icons of the toolbar. For example,
p.setProperty("toolbar", "");
tells the editor to use the simple toolbar used by the MathType Quizzes tools. The definition of the toolbar is the XML fragment:
To learn in detail how to specify the toolbar, visit [[en:mathtype:mathtype_web:features:custom-toolbar|custom toolbar]].
It is possible to define the default styles of the editor. For example, you can change the font size, font family, color and background color.
p.setProperty("backgroundColor", "#008060");
p.setProperty("color", "#ffffff");
p.setProperty("fontSize", "32px");
p.setProperty("fontFamily", "Times New Roman");