注意:這個問題是從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'到目前爲止,雖然當你描述你的問題時,他們覺得我適合這種任務。這就是爲什麼我發佈評論而不是答案:-) –