: I'm making a program that works with chemical equations, but I don't know how to display subscripted and superscripted text. Does anybody know how? :
Not the only way, but perhaps the easiest - use a JEditorPane. If you use HTML, remember that support is only for version 3 - spec is available on http://www.w3.org [code] import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane;
: : I'm making a program that works with chemical equations, but I don't know how to display subscripted and superscripted text. Does anybody know how? : : : : Not the only way, but perhaps the easiest - use a JEditorPane. If you use HTML, remember that support is only for version 3 - spec is available on http://www.w3.org : [code] : import javax.swing.JEditorPane; : import javax.swing.JFrame; : import javax.swing.JScrollPane; : : public class ChemFormulaDisplay extends JFrame { : : private JEditorPane editorPane = : new JEditorPane( : "text/html", : " CH4 x2 "); : : public ChemFormulaDisplay() { : setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); : setSize(300, 300); : : setContentPane(new JScrollPane(editorPane)); : editorPane.setEditable(false); : } : : public static void main(String[] args) { : new ChemFormulaDisplay().show(); : } : } : [/code] : : --------------------------------- : [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
Wow, thank you so much; that works perfectly. And now I don't have to confuse myself to death with GlyphVectors and MutableAttributeSets, because that was getting me nowhere.
Comments
:
Not the only way, but perhaps the easiest - use a JEditorPane. If you use HTML, remember that support is only for version 3 - spec is available on http://www.w3.org
[code]
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class ChemFormulaDisplay extends JFrame {
private JEditorPane editorPane =
new JEditorPane(
"text/html",
" CH4
x2 ");
public ChemFormulaDisplay() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
setContentPane(new JScrollPane(editorPane));
editorPane.setEditable(false);
}
public static void main(String[] args) {
new ChemFormulaDisplay().show();
}
}
[/code]
---------------------------------
[size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
: :
:
: Not the only way, but perhaps the easiest - use a JEditorPane. If you use HTML, remember that support is only for version 3 - spec is available on http://www.w3.org
: [code]
: import javax.swing.JEditorPane;
: import javax.swing.JFrame;
: import javax.swing.JScrollPane;
:
: public class ChemFormulaDisplay extends JFrame {
:
: private JEditorPane editorPane =
: new JEditorPane(
: "text/html",
: " CH4 x2 ");
:
: public ChemFormulaDisplay() {
: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
: setSize(300, 300);
:
: setContentPane(new JScrollPane(editorPane));
: editorPane.setEditable(false);
: }
:
: public static void main(String[] args) {
: new ChemFormulaDisplay().show();
: }
: }
: [/code]
:
: ---------------------------------
: [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
Wow, thank you so much; that works perfectly. And now I don't have to confuse myself to death with GlyphVectors and MutableAttributeSets, because that was getting me nowhere.