Community
Participate
Working Groups
BUG in Fedora Core 1 Linux with SWT 3.0M6 and below. If the background color is set then the row will not appear as selected if it is edited (different behaviour from other rows) The problem is that I need to set the background color because for example before I set the background color to Green and now I want to restore it. It should appear as selected when edited (that is the behaviour on windows) but it is not. Here is the snippet adapted from the standard code. package com.abmira.swt.snippets.control.table; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableEditor; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; public class TableEditor2 { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); 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 < 3; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "" + i, "" + i, "" + i }); if (i == 1) { // BUG in Fedora Core 1 Linux with SWT 3.0M6 and below // If the background color is set then the row will not appear as // selected if it is edited (different behaviour from other rows) // The problem is that I need to set the background color because // for example before I set the background color to Green and now // I want to restore it. It should be selected when edited (that is // the behaviour on windows) but it is not item.setBackground(item.getDisplay().getSystemColor( SWT.COLOR_LIST_BACKGROUND)); } } final TableEditor editor = new TableEditor(table); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; table.addListener(SWT.MouseDown, new Listener() { public void handleEvent(Event event) { Rectangle clientArea = table.getClientArea(); Point pt = new Point(event.x, event.y); int index = table.getTopIndex(); while (index < table.getItemCount()) { boolean visible = false; final TableItem item = table.getItem(index); for (int i = 0; i < table.getColumnCount(); i++) { Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { final int column = i; final Text text = new Text(table, SWT.NONE); Listener textListener = new Listener() { public void handleEvent(final Event e) { switch (e.type) { case SWT.FocusOut : item.setText(column, text.getText()); text.dispose(); break; case SWT.Traverse : switch (e.detail) { case SWT.TRAVERSE_RETURN : item.setText(column, text.getText()); //FALL THROUGH case SWT.TRAVERSE_ESCAPE : text.dispose(); e.doit = false; } break; } } }; text.addListener(SWT.FocusOut, textListener); text.addListener(SWT.Traverse, textListener); editor.setEditor(text, item, i); text.setText(item.getText(i)); text.selectAll(); text.setFocus(); return; } if (!visible && rect.intersects(clientArea)) { visible = true; } } if (!visible) return; index++; } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
Assuming I understand the problem, this works for me. I'll attach an image next that shows what I see. I tried with gtk 2.0.6 and 2.2.1. Does my screenshot not mirror what you see? Changing OS to Linux-GTK.
Created attachment 7341 [details] working (I think) on gtk 2.2.1
FH please try this with gtk 2.2.4.
Well, if I understood the problem, Grant's screenshot shows the bug! In the screenshot, the background of the middle row should be dark blue (or whatever the highlight color is) instead of green. Am I right ?
Another test case. Run the code below, select the Row 0 and then click on the button, note that row 0 preserves the selection background. Repeat the process selecting Row 1, note that when you select the button Row 1 changes the background back to green instead of preserving the selection color. public static void main (String[] args) { Display display = new Display(); Shell shell = new Shell(display); Table table = new Table(shell, SWT.BORDER | SWT.MULTI); for (int i = 0; i < 3; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText("Row " + i); } table.getItem(1).setBackground(display.getSystemColor(SWT.COLOR_GREEN)); table.setBounds(10, 10, 350, 200); Button button = new Button (shell, SWT.PUSH); button.setText("Here"); button.setBounds(10, 220, 60, 30); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
Yes you are correct. Also after setting it to green set it back to SWT.COLOR_LIST_BACKGROUND. It will not show with selected color when selected again. I am doing it on Fedora Core 1.
*** Bug 51584 has been marked as a duplicate of this bug. ***
*** Bug 74769 has been marked as a duplicate of this bug. ***
Bug#30994 is probably the same problem.
The patch here fixes the problem for me: http://bugzilla.gnome.org/show_bug.cgi?id=154611
I think bug 30994 is a different problem.
*** Bug 81430 has been marked as a duplicate of this bug. ***
The patch was included upstream and I verified that this problem no longer occurs on GTK+ 2.6.0 and higher. Maybe we should just disable setting the background colour at all on older versions?
I thought we had already done this.
*** Bug 87450 has been marked as a duplicate of this bug. ***
Bug is in GTK and fixed in later versions. We WONTFIX this.