我有父面板和子面板。父面板上存在子父级。两者都是不同大小的Jpanels。现在我想在子面板上显示一个 ChartPanel。我尝试了各种显示方式,但均未成功。请提出一些将图表添加到 Jpanel 的方法。
抱歉,我无法粘贴代码。我也尝试了stackoverflow Q&A中建议的各种方法,但徒劳无功。
我有父面板和子面板。父面板上存在子父级。两者都是不同大小的Jpanels。现在我想在子面板上显示一个 ChartPanel。我尝试了各种显示方式,但均未成功。请提出一些将图表添加到 Jpanel 的方法。
抱歉,我无法粘贴代码。我也尝试了stackoverflow Q&A中建议的各种方法,但徒劳无功。
因为ChartPanel
建立了首选尺寸并BoxLayout
依赖于首选尺寸,所以让 a使用所需的方向和两者进行newPanel
扩展和to 。Box
add()
child
chartPanel
newPanel
我认为您的问题与 JFreeChart 无关。可能下面的代码可以帮助您开始:
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);