JTabbedPane addTab与add之间有什么区别

时间:2014-03-13 10:46:04

标签: java swing user-interface netbeans jtabbedpane

当我用GUI构建器NetBeans创建简单代码和使用Netbeans创建的第二个代码时,我解决问题并不是我想要的方式。附加屏幕截图是我的应用程序的外观。http://postimg.org/image/6c00csqjn/当我切换标签时,它运行,MathML中的等式将使用JEuclid库呈现,以防我手动编写代码。

但是当我在NetBeans中执行相同操作时,使用构建器执行gui并将渲染代码写入使用netbeans生成的操作事件,然后代码无法正常工作且无法呈现。请有人告诉我哪里有bug?在NetBeans中,我发现只有Netbeans使用.addTab到JTabbedPane而不是.add,因为我应用程序代码如下。

谢谢你的回答

enter image description here

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 = 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);}      
}

1 个答案:

答案 0 :(得分:0)

如果没有阅读您的代码并只撰写问题的答案,这两种方法的区别在于,这里是方法的文档:

  1. add()
  2. addTab()
  3. 两者都是insertTab()的封面方法。