注意:这个问题是从this question后续的问题。如何把JFrame与jmathplot图放入JPanel
我也是刚刚从我的最后一个问题如下:
JPanel
有FLowLayout
(!与相同输出从NullLayout
上调整大小),只接受PreferredSize
,孩子不调整大小与它的容器,需要使用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;
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();
}
});
}
}
现在我想实现的是将图形集成到parent JPanel
中,以便在我的swing应用程序中使用它。
这方面的一个可视化将是:
如何实现我的“父母”的JPanel的图形不违反约束使其正常工作?
(我看着JInternalFrame但未能拿出一个正确的实现我的问题)
如果是JInternalFrame确实是解决方案,我应该如何使用它? (请提供代码)
为什么不看看[JInternalFrame的( http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html),为此任务...?+1,因为你从前一篇文章中学到了很多东西,毫无疑问,天才本人很好地回答了这些问题.-) –
@nIcEcOw你的评论是无法理解的。你是说JInternalFrame的确有解决方案吗? –
是的,我猜是这样,虽然我从来没有碰过'JInternalFrame'到目前为止,虽然当你描述你的问题时,他们觉得我适合这种任务。这就是为什么我发布评论而不是答案:-) –