[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Table/TableEditor flicker problem - 3.2.1 on GTK2

Hi Francis,

The approach of your snippet is fine, the gtk table should not flash like it
is.  I've logged https://bugs.eclipse.org/bugs/show_bug.cgi?id=166785 and
added you as a CC.

The only workaround I can think of is to use custom drawing (demonstrated
below).  The major drawbacks with this are that it's a bit more work, and
the pointer will not automatically change to a hand while hovering over a
"link".

public class Main {
    static int MARGIN = 2;
    public static void main(String[] args) {
        final Display display = new Display ();
        Shell shell = new Shell (display);
        shell.setLayout (new FillLayout ());
        shell.setBounds(10,10,200,200);
        final Table table = new Table (shell, SWT.BORDER | SWT.MULTI);
        table.setLinesVisible (true);
        for (int i=0; i<3; i++) {
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setWidth (100);
        }
        for (int i=0; i<99; i++) {
            TableItem item = new TableItem (table, SWT.NONE);
            for (int j = 0; j < 3; j++) {
                item.setText(j, "item " + i + " col " + j);
            }
        }
        table.addListener(SWT.MeasureItem, new Listener() {
            public void handleEvent(Event event) {
                event.height = event.gc.getFontMetrics().getHeight() + 2;
            }
        });
        table.addListener(SWT.EraseItem, new Listener() {
            public void handleEvent(Event event) {
                event.detail &= ~SWT.FOREGROUND;
            }
        });
        table.addListener(SWT.PaintItem, new Listener() {
            public void handleEvent(Event event) {
                boolean isLink = (table.indexOf((TableItem)event.item)) % 2
!= 0;
                String string =
((TableItem)event.item).getText(event.index);
                GC gc = event.gc;
                if (isLink) {
                    gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
                }
                gc.drawString(string, event.x + MARGIN, event.y);
                if (isLink) {
                    int fontHeight = event.gc.getFontMetrics().getHeight();
                    int stringWidth = gc.textExtent(string).x;
                    gc.drawLine(event.x + MARGIN, event.y + fontHeight,
event.x + MARGIN + stringWidth, event.y + fontHeight);
                }
            }
        });
        shell.open ();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
    }
}

Grant


"Francis Upton" <francisu@xxxxxxxx> wrote in message
news:el26gi$kio$1@xxxxxxxxxxxxxxxxxxxx
> The snippet below works fine on Windows XP, but flickers quite a bit (to
> the point of being unusable on Linux/GTK2).
>
> Any ideas, or should I file a bug?
>
> Also, my real objective here is to embed a Link within a table item.  I
> have been having JFace TableViewer which was working fine, but I could
> not get the Link working with it.  I tried to make a custom CellEditor
> (extending the abstract CellEditor class), but it did not seem to get
> invoked properly to create my custom control.
>
> Any ideas on the best way to proceed in putting a link in a table?
>
> Thanks,
>
> Francis
>
> ----------------------------
>
>
>
> package org.eclipse.swt.snippets;
>
> import org.eclipse.swt.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.custom.*;
>
> public class Snippet126Flicker {
> public static void main(String[] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> shell.setLayout (new GridLayout ());
> Table table = new Table (shell, SWT.BORDER | SWT.MULTI);
>      GridData gd = new GridData(GridData.FILL_BOTH);
>      gd.heightHint = 200;
>      gd.widthHint = 200;
>      table.setLayoutData(gd);
>
>      TableColumn column = new TableColumn(table, SWT.NONE);
> column.setWidth (100);
> for (int i=0; i<100; i++) {
> new TableItem (table, SWT.NONE);
> }
> TableItem [] items = table.getItems ();
> for (int i=0; i<items.length; i++) {
> TableEditor editor = new TableEditor (table);
> editor = new TableEditor (table);
> Text text = new Text (table, SWT.NONE);
> text.setText("Text" + i);
> editor.grabHorizontal = true;
> editor.setEditor(text, items[i], 0);
> editor = new TableEditor (table);
> }
> shell.pack ();
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
> }