[英]How to add ChartPanel to Jpanel in java Swing application
I have parent panel and child panel. 我有父面板和子面板。 child parent exists on parent panel. 子级父级存在于父级面板上。 Both are Jpanels of different size. 两者都是大小不同的Jpanels。 Now i want to show a ChartPanel on the child panel. 现在我想在子面板上显示一个ChartPanel。 I have tried various ways of displaying it but unsucessfull. 我尝试了各种显示方式,但是没有成功。 Please suggest some way of adding chartpanel to Jpanel. 请提出一些将chartpanel添加到Jpanel的方法。
sorry i couldnt paste the code. 抱歉,我无法粘贴代码。 I have also tried various ways suggested in stackoverflow Q&A, but in vain. 我也尝试过各种在stackoverflow问答中建议的方法,但是徒劳。
因为ChartPanel
确定了首选大小,而BoxLayout
依赖于首选大小,所以让newPanel
使用所需的方向扩展Box
add()
child
和chartPanel
都add()
到newPanel
。
I think your problem has nothing to do with JFreeChart. 我认为您的问题与JFreeChart无关。 Probably the code below helps you to start: 以下代码可能会帮助您开始:
JFrame frame = new JFrame();
JPanel parentPanel = new JPanel();
parentPanel.setBorder(BorderFactory.createTitledBorder("parent panel"));
JPanel childPanel = new JPanel();
childPanel.setBorder(BorderFactory.createTitledBorder("child panel"));
// Add a button to the child panel
childPanel.add(new JButton("button"));
// In the instruction below you have to create and add your ChartPanel
childPanel.add(yourChartPanel);
parentPanel.add(childPanel);
frame.add(parentPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.