diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java b/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java index 9fcbeb2b6..4358a728d 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java @@ -177,6 +177,8 @@ public class ColorSchemeComboBox extends UIComboBox { private static final int MAX_COUNT = 5; + private static final int BLANK = 1; + @Override public Dimension getPreferredSize() { Dimension preferredSize = super.getPreferredSize(); @@ -198,7 +200,8 @@ public class ColorSchemeComboBox extends UIComboBox { comp.setText(BLANK_SPACE + schemeName); } else { FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont()); - double width = (HEIGHT - 2 * Y) * MAX_COUNT; + //宽度是5倍的高加上4倍的留白 + double width = (HEIGHT - 2 * Y) * MAX_COUNT + BLANK * (MAX_COUNT - 1); String fill = BLANK_SPACE; //图形和文字之间留的宽度大于3倍的X while (fontMetrics.stringWidth(fill) < width + 3 * X) { @@ -228,7 +231,7 @@ public class ColorSchemeComboBox extends UIComboBox { private void drawGradient(Graphics2D g2d, List colors) { //上下留4px,宽度等于5倍高 double height = HEIGHT - 2 * Y; - double width = height * MAX_COUNT; + double width = height * MAX_COUNT + BLANK * (MAX_COUNT - 1); LinearGradientPaint linearGradientPaint = new LinearGradientPaint((float) X, (float) Y, (float) (X + width), (float) Y, new float[]{0f, 1f}, colors.toArray(new Color[colors.size()])); g2d.setPaint(linearGradientPaint); Rectangle2D rec = new Rectangle2D.Double(X, Y, width, height); @@ -238,10 +241,11 @@ public class ColorSchemeComboBox extends UIComboBox { private void drawCombineColor(Graphics2D g2d, List colors) { int size = Math.min(colors.size(), MAX_COUNT); double height = HEIGHT - 2 * Y; - double width = height * MAX_COUNT / size; + //加上1px留白 + double width = ((height + BLANK) * MAX_COUNT - size) / size; for (int i = 0; i < size; i++) { g2d.setPaint(colors.get(i)); - Rectangle2D rec = new Rectangle2D.Double(X + width * i, Y, width, height); + Rectangle2D rec = new Rectangle2D.Double(X + (width + BLANK) * i, Y, width, height); g2d.fill(rec); } } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java index c66262796..63c24a221 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java @@ -52,7 +52,15 @@ public class VanChartFillStylePane extends BasicBeanPane { this.setLayout(new BorderLayout()); styleSelectBox = new ColorSchemeComboBox(); - customPane = new JPanel(FRGUIPaneFactory.createBorderLayout()); + customPane = new JPanel(FRGUIPaneFactory.createBorderLayout()) { + @Override + public Dimension getPreferredSize() { + if (!gradientSelect) { + return colorAdjustPane.getPreferredSize(); + } + return colorGradient.getPreferredSize(); + } + }; changeColorSetPane = new JPanel(cardLayout = new CardLayout()); changeColorSetPane.add(colorGradient = new FixedGradientBar(4, 130), "gradient"); @@ -119,18 +127,11 @@ public class VanChartFillStylePane extends BasicBeanPane { } protected void initLayout() { + this.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); this.setLayout(new BorderLayout()); this.add(getContentPane(), BorderLayout.CENTER); } - @Override - public Dimension getPreferredSize() { - if (gradientSelect) { - return new Dimension(225, 80); - } - return super.getPreferredSize(); - } - protected JPanel getContentPane() { double p = TableLayout.PREFERRED; double f = TableLayout.FILL;