当前位置: 首页 > 知识库问答 >
问题:

java&JFreeChart-如何设置JFreeChart的图表面板,调整其容器的大小(比如JPanel)?

袁康裕
2023-03-14
    null
ChartPanel chartPanel = new ChartPanel(createWhateverChart());
JFrame frame = new JFrame();
frame.add(chartPanel);
    null
ChartPanel chartPanel = new ChartPanel(createWhateverChart());
JPanel panel = new JPanel("Who cares");
panel.add(chartPanel, BorderLayout.CENTER);
JFrame frame = new JFrame();
frame.add(panel);

共有1个答案

马宜民
2023-03-14

试试我的代码,它很好用。

注意:

我有一个框架,其中包含一个panelMain,panelMain包含一个子面板,子面板包含ChartPanel。

frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));                      
JPanel panelMain = new JPanel(new GridLayout(0,2));            
ChartPanel chartPanel = createChart();        
JPanel subPanel = new JPanel(new BorderLayout());   
subPanel.setBorder(BorderFactory.createTitledBorder("Consommation"));
subPanel.setPreferredSize(new Dimension(400, 200));    
subPanel.add(chartPanel);   


panelMain.add(subPanel);        
frame.add(panelMain);        
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
 类似资料:
  • 问题内容: 我刚刚发现,当我将ChartPanel添加到JFrame时,随着JFrame的拖动或放大或缩小,ChartPanel都会调整大小以适合该框架。但是,当我将ChartPanel添加到JPanel时,随着JFrame调整大小,JPanel的大小(width和height)会更改以适合JFrame。但是,ChartPanel仅保留其尺寸,从而使扩大的JPanel留有很多空白空间。如何在GUI

  • 问题内容: 我似乎无法操纵图表本身。我无法更改大小,并 不断重写为 我试图创建一个方法,但是没有: 范例:http : //www.flickr.com/photos/63259070@N06/6371596517/ 问题答案: 您不必担心图表的大小,将面板的布局设置为GridBagLayout应该会有所帮助。

  • 框架设计采用NetBeans进行。我尝试了所有的解决方案,比如将布局从BorderLayout更改为GridBagLayout,甚至是这里提到的那个。

  • 问题内容: 我在(使用)中添加了一个,它很大。有什么办法可以做得更小? 问题答案: 创建时,你有几个影响结果的选项: 接受和。 指定首选和在构造。 适当时显式调用。 覆盖以动态计算大小。 选择将添加到的容器的布局。需要注意的是默认的布局是,而的是。作为一个具体示例,在构造函数中使用首选值,并在容器中同时使用,以允许动态调整大小。

  • 我创建了一个/图表,但图的大小不相同。顶部的屏幕比下面的小,如屏幕截图所示: 有没有办法设定地块的大小?我希望所有的地块大小相等,不管是2块还是200块。

  • 我已经将添加到中(使用),它很大。我能做点什么让它变小吗?