Within the XYPlot
legend of a chart created with JFreeChart
, I would like items to be arranged with a FlowLayout
arrangement such that excessively long lines are automatically wrapped, however I cannot seem to figure out how to have it so that the items are also center-aligned relative to the entire legend. In other words, I would like line wrapping to remain, but I would like the newly wrapped line to have a HorizontalAlignment.CENTER
as opposed to a HorizontalAlignment.LEFT
.
None of the methods I have yet found in the API or source will allow me to effectively have a centered FlowArrangement
. Is there a convenient way to do this or can I expect to write my own custom Arrangement
based on FlowArrangement
but centered?
The following code snippet is what I had assumed would work, though does not seem to be having any effect on the legend.
LegendTitle chartLegend = chart.getLegend();
chartLegend.setLegendItemGraphicEdge(RectangleEdge.TOP);
chartLegend.getItemContainer().setArrangement(new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.TOP, 0, 0));
EDIT: Another requirement is that the entire graph (with the legend) has to be easily printable, and thus all should be on the same ChartPanel
, and thus I don't see using more than one separate JPanel
as an option.