views:

49

answers:

2

Hello Everyone, 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!

A: 

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 http://stackoverflow.com/questions/457463/putting-jcombobox-into-jtable

brian_d
A: 

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.

camickr
Thank you very much for your answer. I was able to get the editor to look how I wanted it to look, but I'm running into issues with tabbing through the table. If I am in the ComboBox and press tab, it tabs out of the table and onto the first enabled field on the panel that contains the table. Also, if I click the cell where the ComboBox is, things seem to be working correctly, however if I click on the cell where the panel contains the ComboBox is, there seems to be issues. I think it may have something to do with "forwarding these events to the combo box."
Chris Cooley