Avatar
JerzicekX7@gmail.com:

Ahoj, prosil bych o pomoc s řešením vkládání prvků do jTabbedPane ručně.
řeším problém kdy aplikace napsaná v ruce funguje a její verze vytvořená přes NetBeans GUI nikoliv. pro funkčnost je nutné mít importované knihovny JEuclid http://sourceforge.net/…zip/download

aplikace má převádět zápis v MathML do grafické podoby v druhé záložce po přepnutí na ni. předem děkuji za jakékoliv vysvětlení proč se v druhém případě nic nezobrazí

první ruční je:

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.event.ChangeEvent;

import net.sourceforge.jeuclid.swing.JMathComponent;

public class MathMLTabbed extends JFrame{
        private JTextArea formulaSource;
        private JPanel drawingArea, editorArea;
        private JSpinner spinner;
        private JTabbedPane zalozky;

        public MathMLTabbed() {
                this.setTitle("MathML Example");
                this.setSize(500, 500);
                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                Container content = this.getContentPane();

                this.formulaSource = new JTextArea();
                editorArea = new JPanel();
                editorArea.setLayout(new BorderLayout());
                editorArea.add(new JScrollPane(this.formulaSource),BorderLayout.CENTER);
                editorArea.add(spinner = new JSpinner(),BorderLayout.NORTH);
                spinner.setValue(18);

                drawingArea = new JPanel();

                zalozky = new JTabbedPane();
                zalozky.addTab("MathML vstup", editorArea);
                zalozky.addTab("Vzorec", new JScrollPane(drawingArea));
                content.add(zalozky);

                zalozky.addChangeListener(new javax.swing.event.ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        if(zalozky.getSelectedIndex() == 0)
                            drawingArea.removeAll();
                        if(zalozky.getSelectedIndex() == 1)
                            render();
                    }
                });

                String retezec = "<?xml version=\"1.0\"?>\r\n" +
                         "<!DOCTYPE math PUBLIC \"-//W3C//DTD MathML 2.0//EN\" \"http://www.w3.org/TR/MathML2/dtd/mathml2.dtd\">\r\n" +
                         "<math mode=\"display\">\r\n" +
                         "  <mrow>\r\n" +
                         "    <munderover>\r\n" +
                         "      <mo>&#x222B;</mo>\r\n" +
                         "      <mn>1</mn>\r\n" +
                         "      <mi>x</mi>\r\n" +
                         "    </munderover>\r\n" +
                         "    <mfrac>\r\n" +
                         "      <mi>dt</mi>\r\n" +
                         "      <mi>t</mi>\r\n" +
                         "    </mfrac>\r\n" +
                         "  </mrow>\r\n" +
                         "</math>";

                formulaSource.setText(retezec);
        }

        public void render() {
                        // get the text
                        String latex = formulaSource.getText();
                        // create a formula
                        JMathComponent formula = new JMathComponent();
                        drawingArea.add(formula);
                        formula.setFontSize((int)spinner.getValue());
                        formula.setContent(latex);
        }

        public static void main(String[] args) {
                MathMLTabbed frame = new MathMLTabbed();
                frame.setVisible(true);
        }
}

druhá pomocí NetBeans GUI bilder (soubor form)

import net.sourceforge.jeuclid.swing.JMathComponent;

public class okno extends javax.swing.JFrame {

    public okno() {
        initComponents();
        spiner.setValue(18);
        String retezec = "<?xml version=\"1.0\"?>\r\n" +
                         "<!DOCTYPE math PUBLIC \"-//W3C//DTD MathML 2.0//EN\" \"http://www.w3.org/TR/MathML2/dtd/mathml2.dtd\">\r\n" +
                         "<math mode=\"display\">\r\n" +
                         "  <mrow>\r\n" +
                         "    <munderover>\r\n" +
                         "      <mo>&#x222B;</mo>\r\n" +
                         "      <mn>1</mn>\r\n" +
                         "      <mi>x</mi>\r\n" +
                         "    </munderover>\r\n" +
                         "    <mfrac>\r\n" +
                         "      <mi>dt</mi>\r\n" +
                         "      <mi>t</mi>\r\n" +
                         "    </mfrac>\r\n" +
                         "  </mrow>\r\n" +
                         "</math>";

                formulaSource.setText(retezec);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        zalozky = new javax.swing.JTabbedPane();
        MathML = new javax.swing.JPanel();
        spiner = new javax.swing.JSpinner();
        formulaSource = new javax.swing.JTextField();
        vzorec = new javax.swing.JPanel();
        pole = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        zalozky.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                zalozkyStateChanged(evt);
            }
        });

        formulaSource.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        formulaSource.setText("jTextField1");

        javax.swing.GroupLayout MathMLLayout = new javax.swing.GroupLayout(MathML);
        MathML.setLayout(MathMLLayout);
        MathMLLayout.setHorizontalGroup(
            MathMLLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MathMLLayout.createSequentialGroup()
                .addGroup(MathMLLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(formulaSource, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                    .addComponent(spiner))
                .addContainerGap())
        );
        MathMLLayout.setVerticalGroup(
            MathMLLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MathMLLayout.createSequentialGroup()
                .addComponent(spiner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(formulaSource, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE))
        );

        zalozky.addTab("MathML", MathML);

        pole.setBackground(new java.awt.Color(255, 255, 0));

        javax.swing.GroupLayout poleLayout = new javax.swing.GroupLayout(pole);
        pole.setLayout(poleLayout);
        poleLayout.setHorizontalGroup(
            poleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 420, Short.MAX_VALUE)
        );
        poleLayout.setVerticalGroup(
            poleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 354, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout vzorecLayout = new javax.swing.GroupLayout(vzorec);
        vzorec.setLayout(vzorecLayout);
        vzorecLayout.setHorizontalGroup(
            vzorecLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pole, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        vzorecLayout.setVerticalGroup(
            vzorecLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pole, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        zalozky.addTab("Vzorec", vzorec);

        getContentPane().add(zalozky, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>

    private void zalozkyStateChanged(javax.swing.event.ChangeEvent evt) {
        if(zalozky.getSelectedIndex() == 0)
                            pole.removeAll();
        if(zalozky.getSelectedIndex() == 1)
                            render();
    }

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new okno().setVisible(true);
            }
        });

    }

    public void render(){
        String latex = formulaSource.getText();

                        // create a formula
                        JMathComponent formula = new JMathComponent();
                        pole.add(formula);

                        formula.setContent(latex);
                        formula.setFontSize((int)spiner.getValue());
    }

    // Variables declaration - do not modify
    private javax.swing.JPanel MathML;
    private javax.swing.JTextField formulaSource;
    private javax.swing.JPanel pole;
    private javax.swing.JSpinner spiner;
    private javax.swing.JPanel vzorec;
    private javax.swing.JTabbedPane zalozky;
    // End of variables declaration
}
 
Odpovědět 6.3.2014 14:28
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 1 zpráv z 1.