Community
Participate
Working Groups
We started to implement a TableLayout in JFace which tracks table column resizing and adjust other table columns, so that all columns fit into the table's client area. But the table as a standard behavior when a table column is resized (add a horizontal scroll bar). This produces a lot of flickering. To see what I mean run the attached sample code. Try to resize a column to size 0. package com.oti.dbaeumer.swt.tests; import com.ibm.swt.*; import com.ibm.swt.events.*; import com.ibm.swt.graphics.*; import com.ibm.swt.layout.*; import com.ibm.swt.widgets.*; public class TableLayoutTest { Shell shell; Table table; TableColumn tc1, tc2; ResizeListener listener= new ResizeListener(); int fLayoutCounter; private class ResizeListener extends ControlAdapter { public void controlResized(ControlEvent e) { if (fLayoutCounter > 0) return; fLayoutCounter++; TableColumn c= (TableColumn)e.widget; int width= c.getWidth(); if (width < 20) { width= 20; c.setWidth(width); } int available= table.getClientArea().width; int newWidth= available - width; int correct= -1; if (newWidth < 20) { newWidth= 20; correct= available - newWidth; } if (c == tc1) { tc2.setWidth(newWidth); if (correct != -1) tc1.setWidth(correct); } else { tc1.setWidth(newWidth); if (correct != -1) tc2.setWidth(correct); } fLayoutCounter--; } } public TableLayoutTest() { } public TableLayoutTest close () { if ((shell != null) && (!shell.isDisposed ())) shell.dispose (); shell= null; table= null; return this; } public TableLayoutTest open () { shell = new Shell (); shell.setText ("Table Layout Test"); shell.setSize (300, 200); shell.setLayout(new GridLayout()); table= new Table(shell, SWT.BORDER); GridData gd= new GridData(); gd.horizontalAlignment= gd.FILL; gd.grabExcessHorizontalSpace= true; gd.verticalAlignment= gd.FILL; gd.grabExcessVerticalSpace= true; table.setLayoutData(gd); tc1= new TableColumn(table, SWT.NONE); tc1.setText("Column 1"); tc1.addControlListener(listener); tc2= new TableColumn(table, SWT.NONE); tc2.setText("Column 2"); tc2.addControlListener(listener); for (int i= 0; i < 30; i++) { TableItem item= new TableItem(table, SWT.NONE); item.setText(0, "Item " + i + " [0]"); item.setText(1, "Item " + i + " [1]"); } table.setHeaderVisible(true); table.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { if (fLayoutCounter > 0) return; fLayoutCounter++; Rectangle rect= ((Table)e.widget).getClientArea(); tc1.setWidth(rect.width / 2); tc2.setWidth(rect.width / 2); fLayoutCounter--; } }); shell.open (); return this; } public TableLayoutTest run () { Display display = shell.getDisplay (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } return this; } public static void main(java.lang.String[] args) { new TableLayoutTest().open().run().close(); } } NOTES: KH (4/11/00 10:16:27 AM) You will have to deal with the recursive resize callbacks. Setting the column widths may cause the widget to resize and send the programmer a resize event. Making calls that change a widget's size within a resize callback is always dangerous and often lead to recursive death. DB (4/19/00 11:40:32 AM) Only applying the layout strategy once to the table removes the descibed behaviour (for sure it does, because the behaviour only occurs, if the layout is tracked on user changes). McQ (2/1/01 5:00:37 PM) - Information only. CM & SN (3/23/2001 5:28:06 PM) This is the "flickering scrollbars in Table" PR. See also: 1G5WW8R: SWT:Linux - Composite.setBounds causes JFace TableLayout to fail 1FT1OI7: SWT:WINNT - Strange TableEditor behavior CM (3/23/2001 5:39:59 PM) P1/M1 (April 1) SN (3/27/01 6:25:31 PM) This code is close but still has a few problems. It flashes once the first time a scroll bar is required and has not been tested on Motif. I think it is making use of an undocumented Windows feature ... public static void main (String [] args) { final Display display = new Display (); final Shell shell = new Shell (display); final Table table = new Table (shell, 0); table.setHeaderVisible (true); final int columns = 4; for (int i=0; i<columns; i++) { new TableColumn (table, 0); } final int rows = 12; for (int i=0; i<rows; i++) { TableItem item = new TableItem (table, 0); for (int j=0; j<columns; j++) { item.setText (j, "Item " + i + "-" + j); } } shell.addListener (SWT.Resize, new Listener () { public void handleEvent (Event e) { table.setRedraw (false); table.setBounds (shell.getClientArea ()); Rectangle rect = table.getClientArea (); for (int i=0; i<columns; i++) { TableColumn column = table.getColumn (i); column.setWidth (rect.width / columns); } table.setRedraw (true); Rectangle rect2 = table.getClientArea (); if (!rect.equals (rect2)) { table.setRedraw (false); rect.width = rect2.width; for (int i=0; i<columns; i++) { TableColumn column = table.getColumn (i); column.setWidth (rect.width / columns); } table.setRedraw (true); table.update (); } } }); shell.open (); while (!shell.isDisposed()) { if (!display.readAndDispatch ()) display.sleep (); } } CM (3/27/2001 6:40:27 PM) Talked to NE, and he says he doesn't want the new code because he has something that works, and it is too dangerous to put in the new code now. CM (3/28/01 11:46:59 AM) Moving out of Active-Committed.
PRODUCT VERSION: SWT 0.40
*** This bug has been marked as a duplicate of 13467 ***