Eclipse RCP - 自动缩小 TableViwer 单元格中的文本
我正在开发我的第一个 Eclipse RCP 应用程序,我想知道如何强制 JFace TableViewer 组件自动缩小表格单元格内的文本。现在,如果我通过模型传递一个包含多行文本的属性,文本将按原样显示,这会导致表中的每一行具有不同的高度:
我想要的只是一行,最好将该行(如果太长而无法容纳单元格)转换为类似“我是一个非常非常长”的内容lin...' 如果大小窗口更改后,该行变为“我是一个非常非常长的行,住在...”,其中完整的属性是例如。 '我是一个非常非常长的行,位于表格单元格\r\n 和其他一些文本中'。
I'm developing my first Eclipse RCP application and I would like to know how can I force JFace TableViewer component to auto-shrink the text within a table cell. Right now, if I pass through the model a property which contains multi-line text, the text is displayed as is, which causes every row in a table to have different height:
What I want is just a single line, optimally if that line (if its too long to fit the cell) would be converted to something like 'Im a very very long lin...' and if the size of the window changes the line becomes 'Im a very very long line living in a...' where the full property is eg. 'Im a very very long line living in a table cell\r\n and some other text'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不能百分百确定我完全理解你想要什么。
如果您希望从表格单元格文本中删除换行符,则应在设置单元格文本之前使用标准方法 (String.replace()) 执行此操作。
如果您希望调整列宽以适合所有文本,请查看 TableColumn.pack()。
I'm not 100% sure I understand exactly what you want.
If you are looking to remove the new-line's from the table cell text, you should do that using standard methods (String.replace()) before you set the cell text.
If you are looking to resize the column width to fit all the text, check out TableColumn.pack().
最后我按照大卫的建议做了:
Finally I do as David suggested: