jmathplot在swing应用程序中不起作用

我正在尝试在swing应用程序中使用jmathplot库。

问题是,当我将它添加到JPanel时它似乎不起作用,如下所示:

// create your PlotPanel (you can use it as a JPanel) double[] x = new double[] { 0, 1, 2, 3, 4, 5 }; double[] y = new double[] { 10, 11, 12, 14, 15, 16 }; // create your PlotPanel (you can use it as a JPanel) Plot2DPanel graph = new Plot2DPanel(); graph.setBounds(0, 0, 782, 272); // add a line plot to the PlotPanel graph.addLinePlot("my plot", x, y); JPanel panel = new JPanel(); panel.setBounds(10, 333, 782, 272); tab_analysis.add(panel); panel.setLayout(null); panel.add(graph); 

因为情节没有出现,我也得到了奇怪的轴:

在此处输入图像描述

该网站指出:

use the PlotPanel as any Swing component (all PlotPanel extends JPanel, in fact)

我做错了什么?

  • NullLayout一起NullLayout ,没有任何问题,但我对这个布局管理器(委托来自父母的Insets )并不熟悉,然后我留下任何评论

  • 简单的是不要使用NullLayout

  • 覆盖Plot2DPanel getPreferredSize

  • JPanelFLowLayout (与FLowLayout相同的输出!在resize时),仅接受PreferredSize ,子NullLayout不能用其NullLayoutresize,需要使用BorderLayout / GridLayout作为简单图形

在此处输入图像描述

在此处输入图像描述

来自代码

 import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import org.math.plot.Plot2DPanel; public class MyPlot { private JFrame frame = new JFrame("JMathPlot library in a swing application."); private JPanel panel = new JPanel(); public MyPlot() { double[] x = new double[]{0, 1, 2, 3, 4, 5}; double[] y = new double[]{10, 11, 12, 14, 15, 16}; Plot2DPanel plot = new Plot2DPanel() { @Override public Dimension getPreferredSize() { return new Dimension(400, 200); } }; plot.addLinePlot("my plot", x, y); // add a line plot to the PlotPanel panel.setLayout(new BorderLayout()); panel.add(plot); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setLocation(150, 150); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new MyPlot(); } }); } } 

如果你想要Jean-Paul,你可以看到这里的例子:

http://jmathtools.berlios.de/doku.php?id=jmathplot:tutorial