|
|
Re: Text setSelection Issue [message #950278 is a reply to message #950269] |
Fri, 19 October 2012 19:32 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
FWIW here's the test snippet. Each tab has a Composite with two Texts,
so that you can click in the top one and then Tab into the second one to
see its insertion index. All of the tabs initially have their second
Text's insertion indexes at 2, but after ~5.5s the second Text on tab 3
has its insertion index moved to its end (and message "done" output).
Assuming that you aren't looking at tab 3 at the 5.5s mark, this should
replicate your case.
public class ModifiedSnippet76 {
public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell (display);
final TabFolder tabFolder = new TabFolder (shell, SWT.BORDER);
Rectangle clientArea = shell.getClientArea ();
tabFolder.setLocation (clientArea.x, clientArea.y);
for (int i = 0; i < 6; i++) {
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new GridLayout());
TabItem item = new TabItem (tabFolder, SWT.NONE);
item.setText ("TabItem " + i);
item.setControl (composite);
new Text(composite, SWT.SINGLE | SWT.BORDER);
Text text = new Text (composite, SWT.MULTI | SWT.V_SCROLL |
SWT.BORDER);
text.setText ("Page " + i);
text.setSelection(2);
composite.setData(text);
}
display.timerExec(5555, new Runnable() {
public void run() {
Text text = (Text)tabFolder.getItem(3).getControl().getData();
text.setSelection(text.getCharCount());
text.forceFocus(); // <-- not expected to work
System.out.println("done");
}
});
tabFolder.pack ();
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Grant
On 10/19/2012 3:23 PM, Grant Gayed wrote:
> Text.setSelection() should change the caret position in a Text that is
> not currently visible. I've confirmed that this works in the latest SWT
> on Windows (is this the platform that you're using?).
>
> forceFocus() is not expected to work for a control that is not visible,
> as this goes against native behaviors on all supported platforms.
>
> Grant
>
>
> On 10/17/2012 1:02 PM, Nathan Washor wrote:
>> Hi,
>>
>> I seem to have stumbled into a bug. I have one application where the
>> following code works:
>>
>> text.setSelection(text.getCharCount());
>> text.forceFocus();
>>
>> This sets the carat location on an SWT Text (SWT.MULTI | SWT.V_SCROLL)
>> object to the bottom of the text.
>>
>> In my other application, it does not work at all. The difference between
>> the two?
>>
>> In the application where it doesn't work, the text widget is on a
>> composite that is hidden (on a separate tab).
>>
>> Am I missing something here, or is this actually a bug I found?
>>
>> Thanks for any help,
>>
>> Nate
>
|
|
|
Powered by
FUDForum. Page generated in 0.04880 seconds