字符串到 JComponent
我在代码中使用 BalloonTip,并且需要这个构造函数:
public TablecellBalloonTip(JTable table, JComponent component, int row, int column, BalloonTipStyle style, Orientation alignment, AttachLocation attachLocation, int horizontalOffset, int verticalOffset, boolean useCloseButton) {
super(table, component, table.getCellRect(row, column, true), style, alignment, attachLocation, horizontalOffset, verticalOffset, useCloseButton);
setup(table, row, column);
}
在旧版本中,第二个参数是 String 并且它有效,但不再有效。我需要一个字符串到 JComponent 中,但我不知道如何做。
I'm using BalloonTip in my code, and I need this constructor:
public TablecellBalloonTip(JTable table, JComponent component, int row, int column, BalloonTipStyle style, Orientation alignment, AttachLocation attachLocation, int horizontalOffset, int verticalOffset, boolean useCloseButton) {
super(table, component, table.getCellRect(row, column, true), style, alignment, attachLocation, horizontalOffset, verticalOffset, useCloseButton);
setup(table, row, column);
}
In older versions, second parameter was a String and it worked, but not anymore. I need a String into a JComponent then, but I don't know how to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过阅读 API 的 javadoc 和手册(我可以通过简单的 Google 搜索找到它,尽管我以前从未听说过这个 API),可以轻松回答此类问题。
但即使不知道 API,如果它现在需要一个
JComponent
,那是因为它现在能够在气球提示内显示任何类型的组件。由于您只想渲染一些文本,因此使用用字符串初始化的 JLabel 似乎是显而易见的解决方案。This kind of question is easily answered by reading the javadoc and manual of the API (which I was able to find with a simple Google search, although I've never heard of this API before).
But even without knowing the API, if it now takes a
JComponent
, it's because it's now able to display any kind of component inside the balloon tip. Since you want to simply render some text, using aJLabel
initialized with your string seems like the obvious solution.