开发者

JComboBox sizing issue in a table with Multi line Cells

开发者 https://www.devze.com 2023-01-18 07:32 出处:网络
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 correct

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 J开发者_高级运维ComboBoxes. 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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消