Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » text of a Text widget not redraw when resize
text of a Text widget not redraw when resize [message #446150] Wed, 17 November 2004 21:12 Go to next message
jmi is currently offline jmiFriend
Messages: 84
Registered: July 2009
Member
Hi,

I have the next common code. It is a Text widget into a window. Put a long
text into it (the left part has to be invisible) and resize the window. The
content of the widget is the same one as before the resize operation. The
content is not repaint.

What can i do to solve that problem ????

Thanks

JMi

============================================
Windows XP SP2
Eclipse Platform
Version: 3.0.1
Build id: 200409161125
============================================
CODE:
============================================

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
* Used to demonstrate a problem of redraw of the text when the input is
* longer than the widget size.
*
* Make a copy/past of "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and put the carte at the
end.
*
* If you resize the window then the input String is not shown completely.
There
* is only the part displayed before resize which is shown...
*
* Set the focus on the Text widget and the string is show
correctly/completely.
*
* What can i do to solve this problem ?????
*
* I am a newbie with SWT and i don't know how to solve this.
*
*/
public class TestTextRedraw {
static public Text _textCtl;

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);

final GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 5;
layout.marginWidth = 5;
layout.verticalSpacing = 5;
shell.setLayout(layout);

//final Text num3 = new Text(shell, SWT.SINGLE | SWT.WRAP |
SWT.BORDER | SWT.RIGHT);
_textCtl = new Text(shell, SWT.BORDER | SWT.RIGHT);
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
data.heightHint = 20;
_textCtl.setLayoutData(data);

// _textCtl.addListener(SWT.Resize, new Listener() {
// public void handleEvent(final Event argEvent) {
// widgetResize();
// }
// });

shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();

}

// static private void widgetResize() {
// if(_textCtl != null) {
// System.out.println("Redraw widget...");
// _textCtl.redraw();
// }
// }

}
Re: text of a Text widget not redraw when resize [message #446151 is a reply to message #446150] Wed, 17 November 2004 22:13 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Take out the style SINGLE - Single means only one line is shown which will
never wrap.

"JM Delsaux" <JMDelsaux@skynet.be> wrote in message
news:cnges9$377$1@www.eclipse.org...
> Hi,
>
> I have the next common code. It is a Text widget into a window. Put a
> long text into it (the left part has to be invisible) and resize the
> window. The content of the widget is the same one as before the resize
> operation. The content is not repaint.
>
> What can i do to solve that problem ????
>
> Thanks
>
> JMi
>
> ============================================
> Windows XP SP2
> Eclipse Platform
> Version: 3.0.1
> Build id: 200409161125
> ============================================
> CODE:
> ============================================
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> /**
> * Used to demonstrate a problem of redraw of the text when the input is
> * longer than the widget size.
> *
> * Make a copy/past of "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and put the carte at
> the end.
> *
> * If you resize the window then the input String is not shown completely.
> There
> * is only the part displayed before resize which is shown...
> *
> * Set the focus on the Text widget and the string is show
> correctly/completely.
> *
> * What can i do to solve this problem ?????
> *
> * I am a newbie with SWT and i don't know how to solve this.
> *
> */
> public class TestTextRedraw {
> static public Text _textCtl;
>
> public static void main(String[] args) {
> final Display display = new Display();
> final Shell shell = new Shell(display);
>
> final GridLayout layout = new GridLayout();
> layout.numColumns = 1;
> layout.marginHeight = 5;
> layout.marginWidth = 5;
> layout.verticalSpacing = 5;
> shell.setLayout(layout);
>
> //final Text num3 = new Text(shell, SWT.SINGLE | SWT.WRAP |
> SWT.BORDER | SWT.RIGHT);
> _textCtl = new Text(shell, SWT.BORDER | SWT.RIGHT);
> GridData data = new GridData();
> data.horizontalAlignment = GridData.FILL;
> data.grabExcessHorizontalSpace = true;
> data.heightHint = 20;
> _textCtl.setLayoutData(data);
>
> // _textCtl.addListener(SWT.Resize, new Listener() {
> // public void handleEvent(final Event argEvent) {
> // widgetResize();
> // }
> // });
>
> shell.pack();
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
>
> }
>
> // static private void widgetResize() {
> // if(_textCtl != null) {
> // System.out.println("Redraw widget...");
> // _textCtl.redraw();
> // }
> // }
>
> }
>
>
Re: text of a Text widget not redraw when resize [message #446154 is a reply to message #446151] Wed, 17 November 2004 23:20 Go to previous messageGo to next message
jmi is currently offline jmiFriend
Messages: 84
Registered: July 2009
Member
Thanks Veronica but... it is not OK for me

I really need to have only one ligne and i can't use the SWT.WRAP

I use the control to display things with only one ligne (numbers) from the
RIGHT If my number use more area then the displayed one then i have a
problem because the user will probably imagine that he saw everything ->
mistake.

I found a workaround for this problem - i reset the text...

_textCtl.addListener(SWT.Resize, new Listener() {
public void handleEvent(final Event argEvent) {
_textCtl.setText(_textCtl.getText());
}
});

==================================
CODE
==================================
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Event;

/**
* Used to demonstrate a problem of redraw of the text when the input is
longer
* than the widget size.
*
* Make a copy/past of "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and put the carte at the
* end.
*
* If you resize the window then the input String is not shown completely.
There
* is only the part displayed before resize which is shown...
*
* Set the focus on the Text widget and the string is show
correctly/completely.
*
* What can i do to solve this problem ?????
*
* I am a newbie with SWT and i don't know how to solve this.
*
*/
public class TestTextRedraw {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);

final GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 5;
layout.marginWidth = 5;
layout.verticalSpacing = 5;
shell.setLayout(layout);

//final Text num3 = new Text(shell, SWT.SINGLE | SWT.WRAP |
SWT.BORDER
// | SWT.RIGHT);
final Text _textCtl = new Text(shell, SWT.SINGLE | SWT.BORDER
| SWT.RIGHT);
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
data.heightHint = 20;
_textCtl.setLayoutData(data);

_textCtl.addListener(SWT.Resize, new Listener() {
public void handleEvent(final Event argEvent) {
_textCtl.setText(_textCtl.getText());
}
});

shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();

}
}


"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:cngifm$8ni$1@www.eclipse.org...
> Take out the style SINGLE - Single means only one line is shown which will
> never wrap.
>
> "JM Delsaux" <JMDelsaux@skynet.be> wrote in message
> news:cnges9$377$1@www.eclipse.org...
>> Hi,
>>
>> I have the next common code. It is a Text widget into a window. Put a
>> long text into it (the left part has to be invisible) and resize the
>> window. The content of the widget is the same one as before the resize
>> operation. The content is not repaint.
>>
>> What can i do to solve that problem ????
>>
>> Thanks
>>
>> JMi
>>
>> ============================================
>> Windows XP SP2
>> Eclipse Platform
>> Version: 3.0.1
>> Build id: 200409161125
>> ============================================
>> CODE:
>> ============================================
>>
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.layout.GridData;
>> import org.eclipse.swt.layout.GridLayout;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>> import org.eclipse.swt.widgets.Text;
>>
>> /**
>> * Used to demonstrate a problem of redraw of the text when the input is
>> * longer than the widget size.
>> *
>> * Make a copy/past of "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and put the carte at
>> the end.
>> *
>> * If you resize the window then the input String is not shown completely.
>> There
>> * is only the part displayed before resize which is shown...
>> *
>> * Set the focus on the Text widget and the string is show
>> correctly/completely.
>> *
>> * What can i do to solve this problem ?????
>> *
>> * I am a newbie with SWT and i don't know how to solve this.
>> *
>> */
>> public class TestTextRedraw {
>> static public Text _textCtl;
>>
>> public static void main(String[] args) {
>> final Display display = new Display();
>> final Shell shell = new Shell(display);
>>
>> final GridLayout layout = new GridLayout();
>> layout.numColumns = 1;
>> layout.marginHeight = 5;
>> layout.marginWidth = 5;
>> layout.verticalSpacing = 5;
>> shell.setLayout(layout);
>>
>> //final Text num3 = new Text(shell, SWT.SINGLE | SWT.WRAP |
>> SWT.BORDER | SWT.RIGHT);
>> _textCtl = new Text(shell, SWT.BORDER | SWT.RIGHT);
>> GridData data = new GridData();
>> data.horizontalAlignment = GridData.FILL;
>> data.grabExcessHorizontalSpace = true;
>> data.heightHint = 20;
>> _textCtl.setLayoutData(data);
>>
>> // _textCtl.addListener(SWT.Resize, new Listener() {
>> // public void handleEvent(final Event argEvent) {
>> // widgetResize();
>> // }
>> // });
>>
>> shell.pack();
>> shell.open();
>>
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> display.dispose();
>>
>> }
>>
>> // static private void widgetResize() {
>> // if(_textCtl != null) {
>> // System.out.println("Redraw widget...");
>> // _textCtl.redraw();
>> // }
>> // }
>>
>> }
>>
>>
>
>
Re: text of a Text widget not redraw when resize [message #446164 is a reply to message #446154] Thu, 18 November 2004 14:02 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
This is a bug in SWT. I have entered the following bug report:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=78943

As a workaround, instead of calling:

_textCtl.setText(_textCtl.getText());

try:

_textCtl.setSelection(_textCtl.getSelection());

The reason for using the selection approach is because this will preserve
the cursor location and the selection (for the most part - if text is
selected right to left, on resize it will be selected left to right but
there is no way to know in which direction the selection goes).
Re: text of a Text widget not redraw when resize [message #446170 is a reply to message #446164] Thu, 18 November 2004 20:51 Go to previous message
jmi is currently offline jmiFriend
Messages: 84
Registered: July 2009
Member
Thanks Veronika ;-))

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:cnia2l$kv4$1@www.eclipse.org...
> This is a bug in SWT. I have entered the following bug report:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=78943
>
> As a workaround, instead of calling:
>
> _textCtl.setText(_textCtl.getText());
>
> try:
>
> _textCtl.setSelection(_textCtl.getSelection());
>
> The reason for using the selection approach is because this will preserve
> the cursor location and the selection (for the most part - if text is
> selected right to left, on resize it will be selected left to right but
> there is no way to know in which direction the selection goes).
>
Previous Topic:graphics mechanism
Next Topic:Problem with org.eclipse.swt.program.Program
Goto Forum:
  


Current Time: Fri Oct 23 10:50:51 GMT 2020

Powered by FUDForum. Page generated in 0.01556 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top