Eclipse RCP - 自动缩小 TableViwer 单元格中的文本

发布于 2024-11-27 00:33:29 字数 344 浏览 4 评论 0原文

我正在开发我的第一个 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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不吻晚风 2024-12-04 00:33:29

我不能百分百确定我完全理解你想要什么。

如果您希望从表格单元格文本中删除换行符,则应在设置单元格文本之前使用标准方法 (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().

夏雨凉 2024-12-04 00:33:29

最后我按照大卫的建议做了:

col.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            String desc = ((Product) cell.getElement()).getDescription();
            desc = desc.replaceAll("\\r\\n|\\r|\\n", " ");
            cell.setText(desc);
        }
    });

Finally I do as David suggested:

col.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            String desc = ((Product) cell.getElement()).getDescription();
            desc = desc.replaceAll("\\r\\n|\\r|\\n", " ");
            cell.setText(desc);
        }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文