I put my Gantt Chart (ChartPanel) in a JScrollPane,and create a button named [zoom in].
The function for the button [zoom in] is:
When I click [zoom in] button, the width of chart panel will be doubled.
newSize = originalChartWidth * 2;
chartPanel.setPreferredSize(new java.awt.Dimension(newSize, 1000));
After click [zoom in] button, the scroll bar of JScrollPane will be appeared.
Then the user can scroll to watch the whole chart after zoom in.
But there is a problem, When I double the chart panel width, The Task Label Font will be enlarged too.
Before zoom in
After zoom in (The font will be deformed and hard to read)
Is there any way to keep the original font after I double the chart panel width?
Absent a complete example, this appears to be an artifact of adding a ChartPanel
directly to a JscrollPane
. Instead, use a SlidingGanttCategoryDataset
which permits the use of setFirstCategoryIndex()
in response to a scrollbar state change. SlidingGanttDatasetDemo1
is a complete example.
I got the answer to solve my problem.
Call ChartPanel.setMinimumDrawWidth/Height with small value and ChartPanel.setMaximumDrawWidth/Height with large values than exceed the screen size of your monitor. Then, the ChartPanel will be scaled without being distorted.
Please refer to: How to aviod axis label and legend scaling
来源:https://stackoverflow.com/questions/27773120/jfreechart-gantt-chart-task-label-font-size