[英]How to add Balloon Tips to a Cell in JTable,which behave like Tooltips
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. 我希望在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;
}
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. 这只是Balloon Tip
不是我想要的。 Any Suggestions? 有什么建议么?
i think the problem is that you append your ballon tip onto a newly created JLabel... 我认为问题是你将你的气球附加到新创建的JLabel上......
...try to add it onto your renderedCellCopmponent: ...尝试将其添加到您的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... 我希望有效......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.