我的工具提示文字删除了面板。此外,我无法在多行显示大文本。当我将字符串传递给工具提示时,我无法使用<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 :(得分: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;
}
}
并且未解决工具提示错误