gpt4 book ai didi

java - 如何将气球提示添加到 JTable 中的单元格,其行为类似于工具提示

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:01:17 27 4
gpt4 key购买 nike

我要添加Balloon TipsJTable 中的 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 工作,不是我想要的。有什么建议么?

最佳答案

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

...尝试将其添加到您的 renderedCellComponent 中:

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

我希望这行得通...

关于java - 如何将气球提示添加到 JTable 中的单元格,其行为类似于工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28903388/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com