3

I want add Balloon Tips to a Cell in JTable,which behave like Tooltips.I mean when Mouse Entered on a Cell it appear and disappear after some time (same as Tooltips But not a Tooltip).I tried this,but didn't work for me as intended.

@Override
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {

    final JLabel lable = new JLabel(value.toString());

    EdgedBalloonStyle style = new EdgedBalloonStyle(new Color(255, 253, 245),
            new Color(64, 64, 64));
    BalloonTip tooltipBalloon = new BalloonTip(lable, new JLabel(value.toString()), style, new LeftAbovePositioner(15, 10), null);
    ToolTipUtils.balloonToToolTip(tooltipBalloon, 400, 2000);

    return lable;
}

this did nothing. And also I tried this

@Override
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {

    final JLabel lable = new JLabel(value.toString());

    EdgedBalloonStyle style = new EdgedBalloonStyle(new Color(255, 253, 245), new Color(64, 64, 64));
    TablecellBalloonTip tcb = new TablecellBalloonTip(table, new JLabel(value.toString()),
            row, column, style, BalloonTip.Orientation.LEFT_ABOVE,
            BalloonTip.AttachLocation.ALIGNED, 30, 10, false);

    return lable;
}

this is only work as Balloon Tip not what I looking for. Any Suggestions?

1 Answers1

1

i think the problem is that you append your ballon tip onto a newly created JLabel...

...try to add it onto your renderedCellCopmponent:

@Override
public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {

    final JLabel lable = new JLabel(value.toString());

    EdgedBalloonStyle style = new EdgedBalloonStyle(new Color(255, 253, 245), new Color(64, 64, 64));

    //look, here is your mistake: you append it onto a new JLabel
    //TablecellBalloonTip tcb = new TablecellBalloonTip(table, 
    //     new JLabel(value.toString()), row, column, style, 
    //      BalloonTip.Orientation.LEFT_ABOVE,
    //      BalloonTip.AttachLocation.ALIGNED, 30, 10, false);

    //instead append it on your rendered Component
    TablecellBalloonTip tcb = new TablecellBalloonTip(table, 
        lable, // !!here!!
        row, column, style, BalloonTip.Orientation.LEFT_ABOVE,
        BalloonTip.AttachLocation.ALIGNED, 30, 10, false);

    return lable;
}

i hope that works...

Martin Frank
  • 3,445
  • 1
  • 27
  • 47