我想在图例项形状中添加边框。对legendTitle否,但仅对legendItem形状。这是代码的一部分

LegendItemCollection chartLegend = new LegendItemCollection();
Shape legendShape = new Rectangle(10, 10);
LegendItem legendItem = new LegendItem("Text", some color);
legendItem.setLabelFont(new Font(ARIAL_FONT, Font.PLAIN, 8));
legendItem.setShape(legendShape);
chartLegend.add(legendItem);
plot.setFixedLegendItems(chartLegend);

GridArrangement grid = new GridArrangement(3, 1);

LegendTitle legendTitle = new LegendTitle(plot, grid, grid);
legendTitle.setBackgroundPaint(Color.WHITE);
legendTitle.setPosition(RectangleEdge.BOTTOM);
legendTitle.setItemLabelPadding(new RectangleInsets(0, 1, 0, 5));
legendTitle.setPadding(new RectangleInsets(0, 15, 0, 0));
chart.addLegend(legendTitle);

最佳答案

我用那三行代码解决了

legendItem.setLineVisible(true);
legendItem.setLinePaint(Color.BLACK);
legendItem.setLineStroke(new BasicStroke(0.1f));

07-26 02:20