代码之家  ›  专栏  ›  技术社区  ›  Gnoupi

当文本相同时,如何在TableCellRenderer上强制更新工具提示?

  •  2
  • Gnoupi  · 技术社区  · 15 年前

    在Java程序中,我在JTable中为单元格使用自定义渲染器。

    当值不同时,工具提示将更新,并显示在单元格上鼠标指针旁边。

    是否有人知道如何使工具提示在每个单元格上更新,即使使用相同的值?

    3 回复  |  直到 15 年前
        2
  •  1
  •   Tom Hawtin - tackline    15 年前

    添加或删除零宽度、不间断空间?</黑客>

        3
  •  1
  •   Tamara Koliada    6 年前

    尝试将CellStyle用于工具提示更新:

    @Override
    public CellStyle getCellStyleAt(int row, int column) {
            Object property = super.getPropertyAt(row);
            String description = property instanceof Property ? ((Property) property).getDescription() : null;
            if (!StringUtils.isBlank(description)) {
                if (description.length() > splitLength) { // Automatically split long descriptions, store results in cache map.
                    String splitString = descriptionToSplit.get(description);
                    if (null == splitString) {
                        splitString = StringUtils.splitToRows(description, splitLength);
                        descriptionToSplit.put(description, splitString);
                    }
                    cellStyle.setToolTipText(splitString);
                } else { // Optimization for short descriptions.
                    cellStyle.setToolTipText(description);
                }
            } else { // If description is empty, use display name instead.
                String name = property instanceof Property ? ((Property) property).getDisplayName() : null;
                cellStyle.setToolTipText(name);
            }
            return cellStyle;
        }
    
        @Override
        public boolean isCellStyleOn() {
            return true;
        }
    
        private static final CellStyle cellStyle = new CellStyle();