Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Initial Display size of Text widget/Modifying preffered size
Initial Display size of Text widget/Modifying preffered size [message #222463] Tue, 06 April 2004 07:34 Go to next message
Eclipse UserFriend
Originally posted by: sagivijay.yahoo.com

Hi,
I am creating a wizard page by extending WizardPage. In the createControl
method, I create a Text widget and set its initial contents to some
string. When the wizard opens up, I find that the Text box is as long as
the length of the string.
Certain times the Text box becomes awkwardly long.
What I want to do instead is have the size of the Text widget constant so
that I can scroll to read the entire string.
I guess when the composite is laid out it sets its minimum size to that of
the preferred size of this Text widget (which is the length of the
string).
Is it possible to either change the preferred size of this widget or to
set its maximum display size?
I tried using setSize method but no luck.
It will be great if anybody could throw some light on this.
Thanks,
Vijay
Re: Initial Display size of Text widget/Modifying preffered size [message #222755 is a reply to message #222463] Tue, 06 April 2004 09:36 Go to previous messageGo to next message
Eclipse UserFriend
Assuming you're using a layout of some kind (since the text is appearing
without you giving it a size), it's dependent on the semantics of the
layout. For example, if you're using GridLayout then you can set size hints
in the Text's associated GridData object (hHint and wHint).

Grant

"Vijay" <sagivijay@yahoo.com> wrote in message
news:c4u4kq$iqk$1@eclipse.org...
> Hi,
> I am creating a wizard page by extending WizardPage. In the createControl
> method, I create a Text widget and set its initial contents to some
> string. When the wizard opens up, I find that the Text box is as long as
> the length of the string.
> Certain times the Text box becomes awkwardly long.
> What I want to do instead is have the size of the Text widget constant so
> that I can scroll to read the entire string.
> I guess when the composite is laid out it sets its minimum size to that of
> the preferred size of this Text widget (which is the length of the
> string).
> Is it possible to either change the preferred size of this widget or to
> set its maximum display size?
> I tried using setSize method but no luck.
> It will be great if anybody could throw some light on this.
> Thanks,
> Vijay
>
Re: Initial Display size of Text widget/Modifying preffered size [message #223418 is a reply to message #222755] Wed, 07 April 2004 04:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sagivijay.yahoo.com

Hi Grant,
Well I am using GridLayout. heightHint and widthHint specify the minimum
height and width. What I want instead is to be able to specify the maximum
width. Since when I set the initial contents to some arbitrarily long
string, the text box becomes very long.
How can I do this.

Thanks,

Vijay
Grant Gayed wrote:

> Assuming you're using a layout of some kind (since the text is appearing
> without you giving it a size), it's dependent on the semantics of the
> layout. For example, if you're using GridLayout then you can set size hints
> in the Text's associated GridData object (hHint and wHint).

> Grant

> "Vijay" <sagivijay@yahoo.com> wrote in message
> news:c4u4kq$iqk$1@eclipse.org...
> > Hi,
> > I am creating a wizard page by extending WizardPage. In the createControl
> > method, I create a Text widget and set its initial contents to some
> > string. When the wizard opens up, I find that the Text box is as long as
> > the length of the string.
> > Certain times the Text box becomes awkwardly long.
> > What I want to do instead is have the size of the Text widget constant so
> > that I can scroll to read the entire string.
> > I guess when the composite is laid out it sets its minimum size to that of
> > the preferred size of this Text widget (which is the length of the
> > string).
> > Is it possible to either change the preferred size of this widget or to
> > set its maximum display size?
> > I tried using setSize method but no luck.
> > It will be great if anybody could throw some light on this.
> > Thanks,
> > Vijay
> >
Re: Initial Display size of Text widget/Modifying preffered size [message #223586 is a reply to message #223418] Wed, 07 April 2004 09:08 Go to previous messageGo to next message
Eclipse UserFriend
Vijay,

If you're setting the layout hints then these should override the widget's
preferred size. Anyways, the following should demonstrate what you need;
you can change its text.setText(...) line to see it work with shorter or
longer strings.

public static void main(String[] args) {
final int WIDTH_CEILING = 100; // maximum
final Display display = new Display();

final Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new GridLayout());

Text text = new Text(shell, SWT.BORDER);
text.setText("abcdefg hijklmn opqrstuv wxyz");
Point preferredSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int width = Math.min (preferredSize.x, WIDTH_CEILING);
text.setLayoutData(new GridData(width, SWT.DEFAULT));

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

HTH,
Grant

"Vijay" <sagivijay@yahoo.com> wrote in message
news:c50d6h$5b4$1@eclipse.org...
> Hi Grant,
> Well I am using GridLayout. heightHint and widthHint specify the minimum
> height and width. What I want instead is to be able to specify the maximum
> width. Since when I set the initial contents to some arbitrarily long
> string, the text box becomes very long.
> How can I do this.
>
> Thanks,
>
> Vijay
> Grant Gayed wrote:
>
> > Assuming you're using a layout of some kind (since the text is appearing
> > without you giving it a size), it's dependent on the semantics of the
> > layout. For example, if you're using GridLayout then you can set size
hints
> > in the Text's associated GridData object (hHint and wHint).
>
> > Grant
>
> > "Vijay" <sagivijay@yahoo.com> wrote in message
> > news:c4u4kq$iqk$1@eclipse.org...
> > > Hi,
> > > I am creating a wizard page by extending WizardPage. In the
createControl
> > > method, I create a Text widget and set its initial contents to some
> > > string. When the wizard opens up, I find that the Text box is as long
as
> > > the length of the string.
> > > Certain times the Text box becomes awkwardly long.
> > > What I want to do instead is have the size of the Text widget constant
so
> > > that I can scroll to read the entire string.
> > > I guess when the composite is laid out it sets its minimum size to
that of
> > > the preferred size of this Text widget (which is the length of the
> > > string).
> > > Is it possible to either change the preferred size of this widget or
to
> > > set its maximum display size?
> > > I tried using setSize method but no luck.
> > > It will be great if anybody could throw some light on this.
> > > Thanks,
> > > Vijay
> > >
>
>
Re: Initial Display size of Text widget/Modifying preffered size [message #224462 is a reply to message #223586] Thu, 08 April 2004 07:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sagivijay.yahoo.com

Hi Grant,
I never knew that hHint/wHint over-ride the preferred size of a widget.
Thanks a lot for the info. I thought the layout would use the maximum of
the two to compute the intial size and so never actually tried it. It now
works..
However, the code that you have given below the constructor for GridData
takes the following arguments:(int,int)
I however find that it is supposed to be GridData (int style)
I am using Eclipse version 2.1.2.
Is this a new constructor in some latest version?If so what version
Once again thanks a lot for your time and help
Vijay
Grant Gayed wrote:

> Vijay,

> If you're setting the layout hints then these should override the widget's
> preferred size. Anyways, the following should demonstrate what you need;
> you can change its text.setText(...) line to see it work with shorter or
> longer strings.

> public static void main(String[] args) {
> final int WIDTH_CEILING = 100; // maximum
> final Display display = new Display();

> final Shell shell = new Shell(display);
> shell.setBounds(10,10,200,200);
> shell.setLayout(new GridLayout());

> Text text = new Text(shell, SWT.BORDER);
> text.setText("abcdefg hijklmn opqrstuv wxyz");
> Point preferredSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
> int width = Math.min (preferredSize.x, WIDTH_CEILING);
> text.setLayoutData(new GridData(width, SWT.DEFAULT));

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

> HTH,
> Grant

> "Vijay" <sagivijay@yahoo.com> wrote in message
> news:c50d6h$5b4$1@eclipse.org...
> > Hi Grant,
> > Well I am using GridLayout. heightHint and widthHint specify the minimum
> > height and width. What I want instead is to be able to specify the maximum
> > width. Since when I set the initial contents to some arbitrarily long
> > string, the text box becomes very long.
> > How can I do this.
> >
> > Thanks,
> >
> > Vijay
> > Grant Gayed wrote:
> >
> > > Assuming you're using a layout of some kind (since the text is appearing
> > > without you giving it a size), it's dependent on the semantics of the
> > > layout. For example, if you're using GridLayout then you can set size
> hints
> > > in the Text's associated GridData object (hHint and wHint).
> >
> > > Grant
> >
> > > "Vijay" <sagivijay@yahoo.com> wrote in message
> > > news:c4u4kq$iqk$1@eclipse.org...
> > > > Hi,
> > > > I am creating a wizard page by extending WizardPage. In the
> createControl
> > > > method, I create a Text widget and set its initial contents to some
> > > > string. When the wizard opens up, I find that the Text box is as long
> as
> > > > the length of the string.
> > > > Certain times the Text box becomes awkwardly long.
> > > > What I want to do instead is have the size of the Text widget constant
> so
> > > > that I can scroll to read the entire string.
> > > > I guess when the composite is laid out it sets its minimum size to
> that of
> > > > the preferred size of this Text widget (which is the length of the
> > > > string).
> > > > Is it possible to either change the preferred size of this widget or
> to
> > > > set its maximum display size?
> > > > I tried using setSize method but no luck.
> > > > It will be great if anybody could throw some light on this.
> > > > Thanks,
> > > > Vijay
> > > >
> >
> >
Re: Initial Display size of Text widget/Modifying preffered size [message #224479 is a reply to message #224462] Thu, 08 April 2004 08:27 Go to previous message
Eclipse UserFriend
Yes, this constructor is new 3.0 api. It's just equivalent to creating the
GridData and setting its wHint and hHints.

Grant

"Vijay" <sagivijay@yahoo.com> wrote in message
news:c53drh$ec$1@eclipse.org...
> Hi Grant,
> I never knew that hHint/wHint over-ride the preferred size of a widget.
> Thanks a lot for the info. I thought the layout would use the maximum of
> the two to compute the intial size and so never actually tried it. It now
> works..
> However, the code that you have given below the constructor for GridData
> takes the following arguments:(int,int)
> I however find that it is supposed to be GridData (int style)
> I am using Eclipse version 2.1.2.
> Is this a new constructor in some latest version?If so what version
> Once again thanks a lot for your time and help
> Vijay
> Grant Gayed wrote:
>
> > Vijay,
>
> > If you're setting the layout hints then these should override the
widget's
> > preferred size. Anyways, the following should demonstrate what you
need;
> > you can change its text.setText(...) line to see it work with shorter or
> > longer strings.
>
> > public static void main(String[] args) {
> > final int WIDTH_CEILING = 100; // maximum
> > final Display display = new Display();
>
> > final Shell shell = new Shell(display);
> > shell.setBounds(10,10,200,200);
> > shell.setLayout(new GridLayout());
>
> > Text text = new Text(shell, SWT.BORDER);
> > text.setText("abcdefg hijklmn opqrstuv wxyz");
> > Point preferredSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
> > int width = Math.min (preferredSize.x, WIDTH_CEILING);
> > text.setLayoutData(new GridData(width, SWT.DEFAULT));
>
> > shell.open();
> > while (!shell.isDisposed()) {
> > if (!display.readAndDispatch()) display.sleep();
> > }
> > display.dispose();
> > }
>
> > HTH,
> > Grant
>
> > "Vijay" <sagivijay@yahoo.com> wrote in message
> > news:c50d6h$5b4$1@eclipse.org...
> > > Hi Grant,
> > > Well I am using GridLayout. heightHint and widthHint specify the
minimum
> > > height and width. What I want instead is to be able to specify the
maximum
> > > width. Since when I set the initial contents to some arbitrarily long
> > > string, the text box becomes very long.
> > > How can I do this.
> > >
> > > Thanks,
> > >
> > > Vijay
> > > Grant Gayed wrote:
> > >
> > > > Assuming you're using a layout of some kind (since the text is
appearing
> > > > without you giving it a size), it's dependent on the semantics of
the
> > > > layout. For example, if you're using GridLayout then you can set
size
> > hints
> > > > in the Text's associated GridData object (hHint and wHint).
> > >
> > > > Grant
> > >
> > > > "Vijay" <sagivijay@yahoo.com> wrote in message
> > > > news:c4u4kq$iqk$1@eclipse.org...
> > > > > Hi,
> > > > > I am creating a wizard page by extending WizardPage. In the
> > createControl
> > > > > method, I create a Text widget and set its initial contents to
some
> > > > > string. When the wizard opens up, I find that the Text box is as
long
> > as
> > > > > the length of the string.
> > > > > Certain times the Text box becomes awkwardly long.
> > > > > What I want to do instead is have the size of the Text widget
constant
> > so
> > > > > that I can scroll to read the entire string.
> > > > > I guess when the composite is laid out it sets its minimum size to
> > that of
> > > > > the preferred size of this Text widget (which is the length of the
> > > > > string).
> > > > > Is it possible to either change the preferred size of this widget
or
> > to
> > > > > set its maximum display size?
> > > > > I tried using setSize method but no luck.
> > > > > It will be great if anybody could throw some light on this.
> > > > > Thanks,
> > > > > Vijay
> > > > >
> > >
> > >
>
>
Previous Topic:What about the performance of OSGI based runtime?
Next Topic:Client-Server-Installation
Goto Forum:
  


Current Time: Tue Jul 15 03:13:11 EDT 2025

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

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

Back to the top