Source:
<code>public void pack () { checkWidget(); int width = 0; if (buttonHandle != 0) { GtkRequisition requisition = new GtkRequisition (); if (parent.getHeaderVisible() && GTK.GTK_VERSION >= OS.VERSION (3, 8, 0) && !GTK.gtk_widget_get_visible(buttonHandle)) { GTK.gtk_widget_show(buttonHandle); gtk_widget_get_preferred_size (buttonHandle, requisition); GTK.gtk_widget_hide(buttonHandle); } else { gtk_widget_get_preferred_size (buttonHandle, requisition); } width = requisition.width; } if ((parent.style & SWT.VIRTUAL) != 0) { for (int i=0; i<parent.items.length; i++) { TableItem item = parent.items [i]; <START> Rectangle itemBounds = item.getBounds(); <END> Rectangle tableBounds = parent.getBounds(); boolean isVisible = false; if (parent.getHeaderVisible() && GTK.GTK_VERSION >= OS.VERSION (3, 8, 0) && !GTK.gtk_widget_get_visible(buttonHandle)) { isVisible = true; } if (itemBounds.y + itemBounds.height < tableBounds.height && itemBounds.y > 0) { isVisible = true; } if (item != null && item.cached && isVisible) { width = Math.max (width, parent.calculateWidth (handle, item.handle)); } } } else { long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ()); if (GTK.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) { do { width = Math.max (width, parent.calculateWidth (handle, iter)); } while (GTK.gtk_tree_model_iter_next(parent.modelHandle, iter)); } OS.g_free (iter); } setWidthInPixels(width); }</code><technical_language>SWT.VIRTUAL Tables/Trees performance sensitive, a high (sometimes 1000+) number of items. of this need careful of loops number of items, costly. item's height is same, need call this in loop</technical_language>

Target:
public void pack () { checkWidget(); int width = 0; if (buttonHandle != 0) { GtkRequisition requisition = new GtkRequisition (); if (parent.getHeaderVisible() && GTK.GTK_VERSION >= OS.VERSION (3, 8, 0) && !GTK.gtk_widget_get_visible(buttonHandle)) { GTK.gtk_widget_show(buttonHandle); gtk_widget_get_preferred_size (buttonHandle, requisition); GTK.gtk_widget_hide(buttonHandle); } else { gtk_widget_get_preferred_size (buttonHandle, requisition); } width = requisition.width; } if ((parent.style & SWT.VIRTUAL) != 0) { boolean calcWidth = false; Rectangle itemBounds = null; int tableHeight = 0; if (parent.isVisible()) { Rectangle tableBounds = parent.getBounds(); tableHeight = tableBounds.height - parent.getHeaderHeight(); } else { calcWidth = true; } for (int i=0; i<parent.items.length; i++) { TableItem item = parent.items [i]; if (itemBounds == null) itemBounds = item.getBounds(); boolean isVisible = false; if (!calcWidth) { int itemTopBound = itemBounds.y + itemBounds.height * i + i; int itemBottomBound = itemTopBound + itemBounds.height; isVisible = (itemTopBound > 0 && itemBottomBound < tableHeight); } if (item != null && item.cached && (isVisible || calcWidth)) { width = Math.max (width, parent.calculateWidth (handle, item.handle)); } } } else { long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ()); if (GTK.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) { do { width = Math.max (width, parent.calculateWidth (handle, iter)); } while (GTK.gtk_tree_model_iter_next(parent.modelHandle, iter)); } OS.g_free (iter); } setWidthInPixels(width); }