From eabaf76e279611ff62d9384fc1f13d246e3ba1af Mon Sep 17 00:00:00 2001 From: "Richard.Fang" Date: Fri, 18 Oct 2024 16:46:32 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-137698=20fix=E4=BF=AE=E5=A4=8D=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AD=97=E5=85=B8=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=B1=95=E5=BC=80=E6=95=B0=E6=8D=AE=E5=88=97?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datapane/TableDataComboBox.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataComboBox.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataComboBox.java index 3db9c3aff1..6f93848a7e 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataComboBox.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataComboBox.java @@ -1,6 +1,8 @@ package com.fr.design.data.datapane; +import com.fr.design.constants.UIConstants; import java.awt.Component; +import java.awt.Dimension; import java.awt.event.ItemEvent; import java.util.Iterator; import java.util.Map.Entry; @@ -23,7 +25,7 @@ import com.fr.stable.StringUtils; /** * 包含所有数据集的下拉框 - * + * * @author zhou * @since 2012-4-20上午10:34:30 */ @@ -43,22 +45,29 @@ public class TableDataComboBox extends UIComboBox implements Prepare4DataSourceC this.treeName = treeName; this.setRenderer(new UIComboBoxRenderer() { private static final long serialVersionUID = 1L; + private boolean labelVisible = true; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (index == -1 && value == null) { - // 显示空白 + if (value instanceof TableDataWrapper) { + labelVisible = true; + TableDataWrapper tableDataWrapper = (TableDataWrapper)value; + renderer.setIcon(tableDataWrapper.getIcon()); + renderer.setText(tableDataWrapper.getTableDataName()); + renderer.setToolTipText(tableDataWrapper.getTableDataName()); + } else { + labelVisible = false; renderer.setIcon(null); renderer.setText(StringUtils.EMPTY); - }else if (value instanceof TableDataWrapper) { - TableDataWrapper tabledatawrappe = (TableDataWrapper)value; - renderer.setIcon(tabledatawrappe.getIcon()); - renderer.setText(tabledatawrappe.getTableDataName()); - renderer.setToolTipText(tabledatawrappe.getTableDataName()); } return renderer; } + + @Override + public Dimension getPreferredSize() { + return labelVisible ? super.getPreferredSize() : new Dimension(super.getPreferredSize().width, 0); + } }); refresh(source); registerDSChangeListener(); @@ -75,6 +84,7 @@ public class TableDataComboBox extends UIComboBox implements Prepare4DataSourceC setDsMap(); DefaultComboBoxModel model = new DefaultComboBoxModel(); this.setModel(model); + model.addElement(UIConstants.PENDING); // 遍历添加所有数据项到模型 Iterator> entryIt = dsMap.entrySet().iterator(); while (entryIt.hasNext()) { @@ -83,8 +93,6 @@ public class TableDataComboBox extends UIComboBox implements Prepare4DataSourceC model.addElement(tableDataWrapper); } } - // 设置默认选项为空白 - this.setSelectedItem(null); if (dataWrapper != null) { if (DesignTableDataManager.isDsNameChanged(dataWrapper.getTableDataName())) { this.setSelectedTableDataByName(DesignTableDataManager.getChangedDsNameByOldDsName(dataWrapper.getTableDataName()));