Unable to use setSelection() on a List control, after window is created/shown (it has no effect) [message #437162] |
Sat, 29 May 2004 20:55 |
Eclipse User |
|
|
|
Originally posted by: swt.cloudnine.net.nz
Hello everyone!
I've an "interesting issuette" using the recent M9 under linux. I'm
attempting to programatically set the selection of a list, with not much
in the way of results.
I've tried this using the GTK Industrial, Sandy and DebianRed themes (so I
*Assume* it's not a theme based issue, but I could still be wrong). I've
not tried this on anything other than linux yet.
I've attached a code snippet that shows the problem. On my machine,
clicking the button has no effect on the list, but you see the following
output on the console:
Num things selected: 2
list.getSelection() = [1, 2]
So it appears that the call is working, and that internally the List
control thinks it's got two selected items - but nothing changes on screen
(the items are NOT selected).
The interesting twist is that if I perform the selection call directly
inside the createContents() method, it works - but if it's done after the
window is shown (as the snippet does), it doesn't.
Have I missed something obvious? an obvious recent change? or have I found
a bug? (quite happy to file a report, but wanted to check I wasn't being
stupid first)
Regards,
Neil Clayton
--- SAMPLE CODE ----------
public class GUISandbox {
public static void main(String[] args) {
new GUISandbox().run();
}
private void run() {
Shell shell = new Shell();
ApplicationWindow window = new SandboxApplicationWindow(shell);
window.setBlockOnOpen(true);
window.open();
}
private static class SandboxApplicationWindow extends
ApplicationWindow {
public SandboxApplicationWindow(Shell shell) {
super(shell);
}
protected Control createContents(Composite parent) {
parent.setLayout(new FillLayout());
final List list = new List(parent, SWT.MULTI); list.add("1");
list.add("2");
list.add("3");
Button button = new Button(parent, SWT.NONE);
button.setText("Yo world");
button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
list.setSelection(new int[]{0, 1});
System.out.println("Num things selected: " +
list.getSelectionCount());
System.out.println("list.getSelection() = " +
Arrays.asList(list.getSelection()));
}
public void widgetDefaultSelected(SelectionEvent e) { }
});
return parent;
}
}
}
|
|
|
Re: Unable to use setSelection() on a List control, after window is created/shown (it has no effect) [message #437165 is a reply to message #437162] |
Sun, 30 May 2004 08:33 |
Eclipse User |
|
|
|
Originally posted by: swt.cloudnine.net.nz
On Sat, 29 May 2004 21:55:54 +0100, Neil Clayton wrote:
> Hello everyone!
>
> I've an "interesting issuette" using the recent M9 under linux. I'm
> attempting to programatically set the selection of a list, with not much
> in the way of results.
>
> I've tried this using the GTK Industrial, Sandy and DebianRed themes (so I
> *Assume* it's not a theme based issue, but I could still be wrong). I've
> not tried this on anything other than linux yet.
>
> Regards,
> Neil Clayton
-- snip --
I've now narrowed this down to be the same problem mentioned in "List
selection gone when focus is lost", except that it's still happening no
matter what theme I choose. Weird.
Anyone else come across this? I'm using Debian (unstable), a 2.6.5 kernel.
Regards,
Neil Clayton
|
|
|
Powered by
FUDForum. Page generated in 0.02923 seconds