简体   繁体   中英

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. Now i want to show a ChartPanel on the child panel. I have tried various ways of displaying it but unsucessfull. Please suggest some way of adding chartpanel to Jpanel.

sorry i couldnt paste the code. I have also tried various ways suggested in stackoverflow Q&A, but in vain.

因为ChartPanel确定了首选大小,而BoxLayout依赖于首选大小,所以让newPanel使用所需的方向扩展Box add() childchartPaneladd()newPanel

I think your problem has nothing to do with 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM