2015-12-09 60 views
0

我的工具提示文字擦除了面板。此外,我無法在多行顯示大文本。我不能使用<html>標籤,因爲我正在將字符串傳遞給工具提示。任何幫助,不勝感激。在此先感謝...工具提示文字在面板上擦除表格

JTable table = new JTable(dfm) 
{ 
    public String getToolTipText(MouseEvent e) 
       { 
        int row = rowAtPoint(e.getPoint()); 
        int column = columnAtPoint(e.getPoint()); 

        String value = getValueAt(row, column).toString(); 
        return value == null ? null : value; 
       } 
      }; 

回答

0

對於多行顯示錶單元格的數據可以使用如下代碼:

public class MyRenderer extends JTextArea implements TableCellRenderer { 

/** 
* 
*/ 
private static final long serialVersionUID = 1L; 

public MyRenderer() { 
    setLineWrap(true); 
    setWrapStyleWord(true); 
    setOpaque(true); 
} 

@Override 
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 
     int row, int column) { 
    // TODO Auto-generated method stub 
    setText(value.toString());//or something in value, like value.getNote().. 
    if (isSelected) { 
     setForeground(table.getSelectionForeground()); 
     setBackground(table.getSelectionBackground()); 
    } else { 
     setForeground(table.getForeground()); 
     setBackground(table.getBackground()); 
    } 
    setSize(table.getColumnModel().getColumn(column).getWidth(), 
     getPreferredSize().height); 
    if (table.getRowHeight(row) != getPreferredSize().height) { 
     table.setRowHeight(row, getPreferredSize().height); 
    } 
    return this; 
     } 
} 

,並提示錯誤沒有得到解決