具有多行单元格的表格中的 JComboBox 大小问题

发布于 2024-09-25 15:12:42 字数 408 浏览 1 评论 0原文

我最近遇到一个问题,我需要一个可以自动换行的字段,并在文本换行时增加行的高度,类似于 Microsoft Excel。我设法让它正常工作,唯一的问题是该表包含多个 JComboBox。当行的高度从包围文本的字段开始增加时,JComboBox 窗口和 ArrowButton 的大小也会增加。我对 JComboBox 字段使用 DefaultCellEditor,并创建了自己的编辑器/渲染器以与 JTextArea 字段一起使用。一旦选择了 JComboBox 的值,该值就会在字段中正确显示,唯一的问题是当我选择该值时,JComboBox 窗口和 ArrowButton 可能会很大,具体取决于行的大小。有没有办法增加行的高度,但让 JComboBox 字段高度保持不变,而不是增长以填充它所在的列?我想我可能还需要为 JComboBox 字段创建一个自定义单元格编辑器,而不是使用默认值。提前致谢!

I recently had a problem where I needed to have a field that can wrap the text and increase the height of the row as the text is wrapped, similar to Microsoft Excel. I managed to get it working correctly, the only problem is that the table contains multiple JComboBoxes. When the row's height increases from the field that wraps the text, the size of the JComboBox window and ArrowButton also increase. I am using a DefaultCellEditor for the JComboBox fields, and created my own Editor/Renderer to be used with the JTextArea field. Once the JComboBox's value is selected, the value gets displayed correctly in the field, the only problem is while I am selecting the value, the JComboBox window and ArrowButton could be HUGE depending on the size of the row. Is there any way to increase the height of the row, but have the JComboBox field height remain the same instead of growing to fill the column that it's in? I am thinking I might need to make a Custom Cell Editor for the JComboBox fields as well instead of using the default. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

厌味 2024-10-02 15:12:42

我想我可能需要做一个
JComboBox 的自定义单元格编辑器
字段以及而不是使用
默认

这可能是解决方案,因为编辑器的大小是由单元格的大小决定的。

我会尝试使用带有 BorderLayout 的 JPanel 作为编辑器组件。然后将编辑器添加到面板的北部。

这将是最容易创建的编辑器,因为我相信所有鼠标事件和按键事件都传递给编辑器,这意味着面板将获取事件,而不是组合框。所以我想您需要将这些事件转发到组合框。

I am thinking I might need to make a
Custom Cell Editor for the JComboBox
fields as well instead of using the
default

That would probably be the solution since the size of the editor is determined by the size of the cell.

I would try using a JPanel with a BorderLayout as the editor component. Then you add your editor to the North of the panel.

It would be the easiest editor to create since all the mouse events and key events are passed to the editor I believe, which means the panel will get the events, not the combo box. So I guess you would need to forward these events to the combo box.

任谁 2024-10-02 15:12:42

首先,JComboBox 是否位于 BorderLayout 中并设置为 BorderLayout.CENTER
如果是这样,我会将其更改为不同的布局,例如 AbsoluteLayout,这样它就不会拉伸以填充单元格。

另外,我还会向您推荐这篇文章 将 JComboBox 放入 JTable

First, is the JComboBox in a BorderLayout and set to BorderLayout.CENTER?
If so, I'd change it to a different layout such as AbsoluteLayout so it does not stretch to fill the cell.

Also, I will also refer you to this post Putting JComboBox into JTable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文