【问题标题】:How to add Balloon Tips to a Cell in JTable,which behave like Tooltips如何将气球提示添加到 JTable 中的单元格,其行为类似于工具提示
【发布时间】:2015-03-06 16:39:24
【问题描述】:

我想将Balloon Tips 添加到JTable 中的Cell,其行为类似于Tooltips。我的意思是当鼠标进入Cell 时,它会在一段时间后出现并消失(与Tooltips 相同但是不是Tooltip)。我试过了,但没有按预期为我工作。

@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;
}

这什么也没做。 我也试过这个

@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;
}

这只能作为Balloon Tip 工作,而不是我要找的。 有什么建议么?

【问题讨论】:

    标签: java swing tooltip balloon-tip


    【解决方案1】:

    我认为问题在于您将气球提示附加到新创建的 JLabel...

    ...尝试将其添加到您的 renderCellCopmponent:

    @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;
    }
    

    我希望这有效...

    【讨论】:

      猜你喜欢
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      相关资源
      最近更新 更多