• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem understanding event sequence

 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I'm using a JComboBox as the cell editor in a third party table class based on a JTable. I don't think the third party class has anything to do with my problem. Problem is, the combobox opens up being the same width as the column it's in. Often this isn't wide enough to display it's text. I tried with some success to handle the EditingStarted event for the table and resize the combo box like this
(pv.jfcx.JPVTable is the third party class)
pv.jfcx.JPVTable table = jPVTableView.getTable();
int r = table.getEditingRow();
int c = table.getEditingColumn();
//if this is a combo box, tweak it's width
TableColumn col = jPVTableView.getColumn(c);
DefaultCellEditor de = (DefaultCellEditor)col.getCellEditor();
if(de != null)
{
JComboBox cob = (JComboBox)de.getComponent();
int a = cob.getItemCount();
int len = 0;
//find the longest string in the list
for(int b = 0; b < a; b++)
{
my_hwcode str = (my_hwcode)cob.getItemAt(b);
if(str.toString().length() > len)
len =str.toString().length();
}
//if the string is wider than the column, resize it
if((len * 10) > col.getWidth())
{
Rectangle rec = cob.getBounds();
rec.setSize((len * 10), (int)rec.getHeight());
cob.setBounds(rec);
}
doing this in the EditingStarted event handler works when you first click on the combo, but if you open the combo, select something, then open it again some other event handler resizes the pulldown list to the width of the column the second time. I need to know what event is doing this , thats where I need to be putting my code. My real question is how can I figure out the event sequence that occurs when the combobox open up??
Any ideas appreciated
Dave
}
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are all of the columns the same width and height...if not ever consider you might be getting the wrong columns?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!