R D*_*abh 6 java layout swing jfreechart sizing
我添加了JFreeChart一个JPanel(使用a BorderLayout),它是巨大的.有什么我可以做的让它变小吗?
public void generateChart()
{
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//set the values of the chart
for(int i=0; i<8; i++)
{
dataset.setValue(income_array[i], "Income",
Double.toString(percent_array[i]));
}
JFreeChart chart = ChartFactory.createBarChart(
"Required Annual Income for a Variety of Interest Rates",
"Percent", "Income", dataset, PlotOrientation.VERTICAL,
false,true, false);
ChartPanel cp = new ChartPanel(chart);
chart.setBackgroundPaint(Color.white);
chart.getTitle().setPaint(Color.black);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.blue);
//cp.setMaximumDrawHeight(5);
//cp.setMaximumDrawWidth(5);
//cp.setZoomOutFactor(.1);
JPanel graph = new JPanel();
graph.add(cp);
middle.add(graph, BorderLayout.CENTER);
}
Run Code Online (Sandbox Code Playgroud)
tra*_*god 11
创建时ChartPanel,您有几个影响结果的选项:
接受DEFAULT_WIDTH和DEFAULT_HEIGHT:680 x 420.
指定首选width和height在构造.
setPreferredSize()如果合适,则显式调用.
覆盖getPreferredSize()以动态计算大小.
@Override
public Dimension getPreferredSize() {
// given some values of w & h
return new Dimension(w, h);
}
Run Code Online (Sandbox Code Playgroud)选择要添加的容器的布局ChartPanel.请注意,默认布局JPanel是FlowLayout,JFrame而是BorderLayout.作为一个具体示例,ThermometerDemo在构造函数中使用首选值,GridLayout对容器使用允许动态调整大小的值.

| 归档时间: |
|
| 查看次数: |
13582 次 |
| 最近记录: |