diff --git a/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class b/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class index 9ff7d87..1087ebf 100644 Binary files a/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class and b/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class differ diff --git a/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java b/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java index 2819fa4..426130d 100644 --- a/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java +++ b/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java @@ -41,6 +41,7 @@ public class JTreeComboBox extends JComboBox { @Override public void valueChanged(TreeSelectionEvent e) { if (!suppressEvents) { + System.out.println("更新选中项!"); DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (selectedNode != null) { setSelectedItem(selectedNode); @@ -90,23 +91,41 @@ public class JTreeComboBox extends JComboBox { } }); + // 设置整个 JComboBox 的 renderer + this.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + if (value instanceof DefaultMutableTreeNode) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; + value = node.getUserObject(); // 使用节点的用户对象作为显示内容 + } + return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + } + }); + // 初始选择根节点 setSelectedItem(root); System.out.println("JTreeComboBox初始化完成"); + + } @Override public void setSelectedItem(Object anObject) { + System.out.println("设置选中项: " + anObject); suppressEvents = true; super.setSelectedItem(anObject); suppressEvents = false; // 更新树的选择状态 + System.out.println("选中项类型 = "+anObject.getClass().getTypeName()); if (anObject instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) anObject; TreePath path = new TreePath(node.getPath()); tree.setSelectionPath(path); + }else { + System.out.println("选中项:"+anObject+"不是DefaultMutableTreeNode类型,设置选中项失败!"); } revalidate(); // 触发布局更新 repaint(); // 触发重绘