Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » initial size of a tableviewer
initial size of a tableviewer [message #446571] Fri, 26 November 2004 17:14 Go to next message
Eclipse UserFriend
Originally posted by: tom_edwards.gmx.net

Hi!
How can I set the initial size of a table viewer? I use a scrollable form
and inside this form I added a table viewer. Now I would like to set the
initial height of the table but what happens is that the whole table is
shown and the user has to scroll the whole form instead of the table.
So far I tried to set the size using
table.setSize(..) and table.setBounds(..) but nothing changed.
Does anyone know how the initial size of a table viewer can be set?
TIA, Tom
Re: initial size of a tableviewer [message #446577 is a reply to message #446571] Fri, 26 November 2004 17:34 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
You need to create a layout for the parent of the widgets in the scrolled
composite and depending on the type of that layout, you need to constrain
the height of the table. For example, below I have used a GridLayout:

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL |
SWT.V_SCROLL);
Composite parent = new Composite(sc, SWT.NONE);
parent.setLayout(new GridLayout());
Table table = new Table(parent, SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
data.heightHint = 10 * table.getItemHeight();
table.setLayoutData(data);
for (int i = 0; i < 100; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("item "+i);
}
for (int i = 0; i < 20; i++) {
Button b = new Button(parent, SWT.PUSH);
b.setText("Button "+i);
}
sc.setContent(parent);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

"Tom Edwards" <tom_edwards@gmx.net> wrote in message
news:co7oac$4f0$1@www.eclipse.org...
> Hi!
> How can I set the initial size of a table viewer? I use a scrollable form
> and inside this form I added a table viewer. Now I would like to set the
> initial height of the table but what happens is that the whole table is
> shown and the user has to scroll the whole form instead of the table. So
> far I tried to set the size using
> table.setSize(..) and table.setBounds(..) but nothing changed.
> Does anyone know how the initial size of a table viewer can be set?
> TIA, Tom
>
Re: initial size of a tableviewer [message #446629 is a reply to message #446577] Tue, 30 November 2004 06:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tom_edwards.gmx.net

Hi Veronika,
Thanks for your answer. It works using the grid layout for the parent. My
table has the expected height. But the problem I have now is that the
table doesn't resize at all. What I would like to have is a table which
has as initial height the value I specify but which resizes while resizing
the scrolled form. How can I achieve this?
TIA, Tom


Veronika Irvine wrote:

> You need to create a layout for the parent of the widgets in the scrolled
> composite and depending on the type of that layout, you need to constrain
> the height of the table. For example, below I have used a GridLayout:

> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> shell.setLayout(new FillLayout());
> ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL |
> SWT.V_SCROLL);
> Composite parent = new Composite(sc, SWT.NONE);
> parent.setLayout(new GridLayout());
> Table table = new Table(parent, SWT.BORDER);
> GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
> data.heightHint = 10 * table.getItemHeight();
> table.setLayoutData(data);
> for (int i = 0; i < 100; i++) {
> TableItem item = new TableItem(table, SWT.NONE);
> item.setText("item "+i);
> }
> for (int i = 0; i < 20; i++) {
> Button b = new Button(parent, SWT.PUSH);
> b.setText("Button "+i);
> }
> sc.setContent(parent);
> sc.setExpandHorizontal(true);
> sc.setExpandVertical(true);
> sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }

> "Tom Edwards" <tom_edwards@gmx.net> wrote in message
> news:co7oac$4f0$1@www.eclipse.org...
>> Hi!
>> How can I set the initial size of a table viewer? I use a scrollable form
>> and inside this form I added a table viewer. Now I would like to set the
>> initial height of the table but what happens is that the whole table is
>> shown and the user has to scroll the whole form instead of the table. So
>> far I tried to set the size using
>> table.setSize(..) and table.setBounds(..) but nothing changed.
>> Does anyone know how the initial size of a table viewer can be set?
>> TIA, Tom
>>
Re: initial size of a tableviewer [message #446694 is a reply to message #446629] Tue, 30 November 2004 18:12 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Replace:

GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);

with:

GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);


"Tom Edwards" <tom_edwards@gmx.net> wrote in message
news:coh51u$rji$1@www.eclipse.org...
> Hi Veronika,
> Thanks for your answer. It works using the grid layout for the parent. My
> table has the expected height. But the problem I have now is that the
> table doesn't resize at all. What I would like to have is a table which
> has as initial height the value I specify but which resizes while resizing
> the scrolled form. How can I achieve this?
> TIA, Tom
>
>
> Veronika Irvine wrote:
>
>> You need to create a layout for the parent of the widgets in the scrolled
>> composite and depending on the type of that layout, you need to constrain
>> the height of the table. For example, below I have used a GridLayout:
>
>> public static void main (String [] args) {
>> Display display = new Display ();
>> Shell shell = new Shell (display);
>> shell.setLayout(new FillLayout());
>> ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL
>> | SWT.V_SCROLL);
>> Composite parent = new Composite(sc, SWT.NONE);
>> parent.setLayout(new GridLayout());
>> Table table = new Table(parent, SWT.BORDER);
>> GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
>> data.heightHint = 10 * table.getItemHeight();
>> table.setLayoutData(data);
>> for (int i = 0; i < 100; i++) {
>> TableItem item = new TableItem(table, SWT.NONE);
>> item.setText("item "+i);
>> }
>> for (int i = 0; i < 20; i++) {
>> Button b = new Button(parent, SWT.PUSH);
>> b.setText("Button "+i);
>> }
>> sc.setContent(parent);
>> sc.setExpandHorizontal(true);
>> sc.setExpandVertical(true);
>> sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
>> shell.open ();
>> while (!shell.isDisposed ()) {
>> if (!display.readAndDispatch ()) display.sleep ();
>> }
>> display.dispose ();
>> }
>
>> "Tom Edwards" <tom_edwards@gmx.net> wrote in message
>> news:co7oac$4f0$1@www.eclipse.org...
>>> Hi!
>>> How can I set the initial size of a table viewer? I use a scrollable
>>> form and inside this form I added a table viewer. Now I would like to
>>> set the initial height of the table but what happens is that the whole
>>> table is shown and the user has to scroll the whole form instead of the
>>> table. So far I tried to set the size using
>>> table.setSize(..) and table.setBounds(..) but nothing changed.
>>> Does anyone know how the initial size of a table viewer can be set?
>>> TIA, Tom
>>>
>
>
Re: resizing problem of table viewer in scrolled form [message #446745 is a reply to message #446694] Thu, 02 December 2004 09:40 Go to previous message
Eclipse UserFriend
Originally posted by: tom_edwards.gmx.net

Veronika,
Unfortunately your suggestion does not work im my case. I use a scrolled
form with TableWrapLayout. I could set the initial height but I have no
idea how to render the table viewer resizable. When I resize my form then
the table viewer size stays the same all the time.
I would appreciate it if you or someone else could give me a hint. Below
you can see the code I use:

ScrolledForm form = managedForm.getForm();
FormToolkit toolkit = managedForm.getToolkit();
Composite body = managedForm.getForm().getBody();
//crate layout of the body
TableWrapLayout layout = new TableWrapLayout();
layout.numColumns = 2;
TableWrapData wd = new TableWrapData();
wd.grabVertical = true;
wd.grabHorizontal = true;
body.setLayout(layout);
body.setLayoutData(wd);
//create the sections in the body
managedForm.addPart(createListSection());

in another class -> list section is created
DBEditorSection section = new DBEditorSection(
page, parent, Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED
section.setText("Collection Extent");
TableWrapData td = new
TableWrapData(TableWrapData.FILL_GRAB,TableWrapData.FILL_GRA B);
section.setLayoutData(td);
//create a composite for client area containing the collection member
table
Composite client = toolkit.createComposite(section);
client.setLayout(new GridLayout());
section.setClient(client);
//create table viewer
TableViewer collectionViewer = new TableViewer(
parent, SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
Table table = collectionViewer.getTable();
//set table layout data
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.heightHint = 25 * table.getItemHeight();
gridData.grabExcessVerticalSpace = true;
table.setLayoutData(gridData);

------------------------------------------------------------ ----------------
Veronika Irvine wrote:

> Replace:

> GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);

> with:

> GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);


> "Tom Edwards" <tom_edwards@gmx.net> wrote in message
> news:coh51u$rji$1@www.eclipse.org...
>> Hi Veronika,
>> Thanks for your answer. It works using the grid layout for the parent. My
>> table has the expected height. But the problem I have now is that the
>> table doesn't resize at all. What I would like to have is a table which
>> has as initial height the value I specify but which resizes while resizing
>> the scrolled form. How can I achieve this?
>> TIA, Tom
>>
>>
>> Veronika Irvine wrote:
>>
>>> You need to create a layout for the parent of the widgets in the scrolled
>>> composite and depending on the type of that layout, you need to constrain
>>> the height of the table. For example, below I have used a GridLayout:
>>
>>> public static void main (String [] args) {
>>> Display display = new Display ();
>>> Shell shell = new Shell (display);
>>> shell.setLayout(new FillLayout());
>>> ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL
>>> | SWT.V_SCROLL);
>>> Composite parent = new Composite(sc, SWT.NONE);
>>> parent.setLayout(new GridLayout());
>>> Table table = new Table(parent, SWT.BORDER);
>>> GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
>>> data.heightHint = 10 * table.getItemHeight();
>>> table.setLayoutData(data);
>>> for (int i = 0; i < 100; i++) {
>>> TableItem item = new TableItem(table, SWT.NONE);
>>> item.setText("item "+i);
>>> }
>>> for (int i = 0; i < 20; i++) {
>>> Button b = new Button(parent, SWT.PUSH);
>>> b.setText("Button "+i);
>>> }
>>> sc.setContent(parent);
>>> sc.setExpandHorizontal(true);
>>> sc.setExpandVertical(true);
>>> sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
>>> shell.open ();
>>> while (!shell.isDisposed ()) {
>>> if (!display.readAndDispatch ()) display.sleep ();
>>> }
>>> display.dispose ();
>>> }
>>
>>> "Tom Edwards" <tom_edwards@gmx.net> wrote in message
>>> news:co7oac$4f0$1@www.eclipse.org...
>>>> Hi!
>>>> How can I set the initial size of a table viewer? I use a scrollable
>>>> form and inside this form I added a table viewer. Now I would like to
>>>> set the initial height of the table but what happens is that the whole
>>>> table is shown and the user has to scroll the whole form instead of the
>>>> table. So far I tried to set the size using
>>>> table.setSize(..) and table.setBounds(..) but nothing changed.
>>>> Does anyone know how the initial size of a table viewer can be set?
>>>> TIA, Tom
>>>>
>>
>>
Previous Topic:How to set a TableColumn-type?!?
Next Topic:[MacOS X.3.6] laucnching an swt app using Info.plist
Goto Forum:
  


Current Time: Sun Oct 25 09:04:41 GMT 2020

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

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

Back to the top