对jtable的每个cell设置tooltiptext,当鼠标移动到那个cell时,会显示相应的tooltiptext,这是很多例子都有的;
但是如何做到保存或者输出cell的每个tooltiptext呢?

解决方案 »

  1.   

    什么叫保存或者输出?其实你可以在构造你的JTable的时候做这种事情,把你的所有提示也放到一个模型里面,这个模型和TableModel相对应,然后把每个对应的cell设置为其对应的TooltipText就可以了
      

  2.   

    既然能够作为ToolTip显示,说明总是有数据源及相应算法的,
    需要保存或输出的时候将这个数据源按需要的顺序保存或输出不就行了。
      

  3.   

    这样的例子一般应该重写了cell的CellRenderer,你可以检查一下,在它的CellRenderer中是不是有类似getTooltips之类的方法
      

  4.   

    Unfortunately, there is no setToolTipText() method for cells in a JTable component. For a cell to show a tool tip, the renderer for that cell must set the tool tip text on the returned component. If you cannot modify the renderer, you can override the table's prepareRenderer() method and explicitly set the tool tip on the returned component.     // This table displays a tool tip text based on the string
        // representation of the cell value
        JTable table = new JTable() {
            public Component prepareRenderer(TableCellRenderer renderer,
                                             int rowIndex, int vColIndex) {
                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
                if (c instanceof JComponent) {
                    JComponent jc = (JComponent)c;
                    jc.setToolTipText((String)getValueAt(rowIndex, vColIndex));
                }
                return c;
            }
        };