| | |
| | | contentPanel.remove(contentPanel.getComponentCount() - 1); |
| | | } |
| | | |
| | | // 直接添加内容面板,不使用滚动条 |
| | | // 添加图例内容面板 |
| | | mainPanel.add(contentPanel, BorderLayout.CENTER); |
| | | |
| | | getContentPane().add(mainPanel); |
| | |
| | | |
| | | return itemPanel; |
| | | } |
| | | |
| | | /** |
| | | * 加载并缩放图标 |
| | | * @param iconPath 图标路径 |
| | | * @param width 目标宽度 |
| | | * @param height 目标高度 |
| | | * @return 缩放后的图标 |
| | | */ |
| | | private ImageIcon loadIcon(String iconPath, int width, int height) { |
| | | try { |
| | | java.net.URL imgURL = getClass().getClassLoader().getResource(iconPath); |
| | | if (imgURL == null) { |
| | | // 尝试从文件系统加载 |
| | | java.io.File imgFile = new java.io.File(iconPath); |
| | | if (imgFile.exists()) { |
| | | ImageIcon originalIcon = new ImageIcon(imgFile.getAbsolutePath()); |
| | | Image scaledImage = originalIcon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); |
| | | ImageIcon scaledIcon = new ImageIcon(scaledImage); |
| | | scaledIcon.setDescription(iconPath); |
| | | return scaledIcon; |
| | | } |
| | | } else { |
| | | ImageIcon originalIcon = new ImageIcon(imgURL); |
| | | Image scaledImage = originalIcon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); |
| | | ImageIcon scaledIcon = new ImageIcon(scaledImage); |
| | | scaledIcon.setDescription(iconPath); |
| | | return scaledIcon; |
| | | } |
| | | } catch (Exception e) { |
| | | System.err.println("无法加载图标: " + iconPath + " - " + e.getMessage()); |
| | | } |
| | | return null; |
| | | } |
| | | } |