Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table doesn't stretch to fit window
Table doesn't stretch to fit window [message #446261] Mon, 22 November 2004 22:42 Go to next message
Eclipse UserFriend
Originally posted by: ukalumni.hotmail.com

I've got a class to define a table. I make the following calls:

FaxListTable flt = new FaxListTable();
flt.addFaxTable(composite);

FaxListTable.addFaxTable(Composite composite) looks like this:

protected Control addFaxTable(Composite parent){
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
tv.setContentProvider(new FaxTableContentProvider());
tv.setLabelProvider(new FaxTableLabelProvider());
tv.setInput(faxes);
Table table = tv.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
new TableColumn(table, SWT.CENTER).setText(FILE_NAME);
new TableColumn(table, SWT.CENTER).setText(ORDER_DATE);
new TableColumn(table, SWT.CENTER).setText(STATUS);
new TableColumn(table, SWT.CENTER).setText(USER);
for(int i = 0, n = table.getColumnCount(); i < n; i++)
{
table.getColumn(i).pack();
}
table.setHeaderVisible(true);
table.setLinesVisible(true);
tv.setColumnProperties(props);
tv.refresh();
composite.pack();
return composite;
}

I get the table, but it doesn't stretch to the full size of the parent
composite, and it doesn't respond if I resize the parent composite.

Anyone see something I'm missing?

Thanks,
--Michael
Re: Table doesn't stretch to fit window [message #446294 is a reply to message #446261] Tue, 23 November 2004 09:02 Go to previous messageGo to next message
Horst Dehmer is currently offline Horst DehmerFriend
Messages: 18
Registered: July 2009
Junior Member
Hi Michael,

check out SwtForms layout manager (http://ffxml.net/swtforms/).
Since I use this one I have no need to use any build-in manager.
SwtForms is derived from a Swing layout manager. If you can't
find the docs, check out JGoodies Forms
(http://www.jgoodies.com/downloads/libraries.html).

Suppose your table's the only component in the view/dialog the
following might accomplish what you want:

import net.ffxml.swtforms.builder.PanelBuilder;
import net.ffxml.swtforms.layout.CellConstraints;
import net.ffxml.swtforms.layout.FormLayout;

....

public void createPartControl(Composite parent) {
Composite contents = new Composite(parent, SWT.NONE);
final String columnSpec = "fill:pref:grow";
final String rowSpec = "fill:pref:grow";

FormLayout layout = new FormLayout(columnSpec, rowSpec);
CellConstraints cc = new CellConstraints();
PanelBuilder builder = new PanelBuilder(contents, layout);
TableViewer viewer = new TableViewer(contents, SWT.BORDER);
builder.add(viewer.getControl(), cc.xy(1, 1));
}

Hope this helps,
Horst

"Michael Molloy" <ukalumni@hotmail.com> schrieb im Newsbeitrag
news:cntq8n$d00$1@www.eclipse.org...
> I've got a class to define a table. I make the following calls:
>
> FaxListTable flt = new FaxListTable();
> flt.addFaxTable(composite);
>
> FaxListTable.addFaxTable(Composite composite) looks like this:
>
> protected Control addFaxTable(Composite parent){
> Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new GridLayout(1, false));
> final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
> tv.setContentProvider(new FaxTableContentProvider());
> tv.setLabelProvider(new FaxTableLabelProvider());
> tv.setInput(faxes);
> Table table = tv.getTable();
> table.setLayoutData(new GridData(GridData.FILL_BOTH));
> new TableColumn(table, SWT.CENTER).setText(FILE_NAME);
> new TableColumn(table, SWT.CENTER).setText(ORDER_DATE);
> new TableColumn(table, SWT.CENTER).setText(STATUS);
> new TableColumn(table, SWT.CENTER).setText(USER);
> for(int i = 0, n = table.getColumnCount(); i < n; i++)
> {
> table.getColumn(i).pack();
> }
> table.setHeaderVisible(true);
> table.setLinesVisible(true);
> tv.setColumnProperties(props);
> tv.refresh();
> composite.pack();
> return composite;
> }
>
> I get the table, but it doesn't stretch to the full size of the parent
> composite, and it doesn't respond if I resize the parent composite.
>
> Anyone see something I'm missing?
>
> Thanks,
> --Michael
>
Re: Table doesn't stretch to fit window [message #446338 is a reply to message #446294] Tue, 23 November 2004 14:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ukalumni.hotmail.com

Thanks for the suggestion. I may look into it, but for the time being, I
would really like to get this working without introducing something else
new into my code.

The problem is that I can find no way to successfully call
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on the
composite that contains my table.

The table stretches to fill the composite it is sitting in, but that
composite doesn't fill it's parent composite. Whenever I try setting the
layoutData on the table's composite, I get the following error:

Not a button: java.lang.ClassCastException
java.lang.ClassCastException

and a stacktrace.

Thanks,
--Michael

Horst Dehmer wrote:
> Hi Michael,
>
Re: Table doesn't stretch to fit window [message #446339 is a reply to message #446338] Tue, 23 November 2004 14:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ukalumni.hotmail.com

One more update. I tried removing the table from it's own composite and
stuck it in the parent composite, but I'm still getting the same
exception listed below.

Any ideas, anyone?

Thanks,
--Michael

Michael Molloy wrote:
> Thanks for the suggestion. I may look into it, but for the time being, I
> would really like to get this working without introducing something else
> new into my code.
>
> The problem is that I can find no way to successfully call
> composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on the
> composite that contains my table.
>
> The table stretches to fill the composite it is sitting in, but that
> composite doesn't fill it's parent composite. Whenever I try setting the
> layoutData on the table's composite, I get the following error:
>
> Not a button: java.lang.ClassCastException
> java.lang.ClassCastException
>
> and a stacktrace.
>
> Thanks,
> --Michael
>
> Horst Dehmer wrote:
>
>> Hi Michael,
>>
Re: Table doesn't stretch to fit window--SOLVED [message #446340 is a reply to message #446339] Tue, 23 November 2004 14:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ukalumni.hotmail.com

Apparently you can't put a Table into a composite that uses a RowLayout
*and* call setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on one
of the controls in the composite (or a child composite, as it turns out).

If I removed the TableViewer.setLayoutData call, the table appears as
expected, and it doesn't stretch with the window, also as expected.
However, uncommenting the setLayoutData line causes it to crash.

Is this a bug or a limitation of RowLayout somehow?

Thanks,
--Michael

Michael Molloy wrote:
> One more update. I tried removing the table from it's own composite and
> stuck it in the parent composite, but I'm still getting the same
> exception listed below.
>
> Any ideas, anyone?
>
> Thanks,
> --Michael
>
> Michael Molloy wrote:
>
>> Thanks for the suggestion. I may look into it, but for the time being,
>> I would really like to get this working without introducing something
>> else new into my code.
>>
>> The problem is that I can find no way to successfully call
>> composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on the
>> composite that contains my table.
>>
>> The table stretches to fill the composite it is sitting in, but that
>> composite doesn't fill it's parent composite. Whenever I try setting
>> the layoutData on the table's composite, I get the following error:
>>
>> Not a button: java.lang.ClassCastException
>> java.lang.ClassCastException
>>
>> and a stacktrace.
>>
>> Thanks,
>> --Michael
>>
>> Horst Dehmer wrote:
>>
>>> Hi Michael,
>>>
Re: Table doesn't stretch to fit window--SOLVED [message #446356 is a reply to message #446340] Tue, 23 November 2004 18:42 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
RowLayout uses RowData and GridLayout uses GridData. You can not mix the
two together. The layout on the parent composite must match the layout data
on the immediate children in that composite.
If you change the layout on the parent composite to GridLayout, then you can
use GridData.

If you only have one child in the parent composite and you want the child to
take up all of the room and be stretched you could just use FillLayout which
requires no data.

Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
Table table = tv.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));

is equal to:

Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FillLayout());
final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);


"Michael Molloy" <ukalumni@hotmail.com> wrote in message
news:cnvik0$9h5$1@www.eclipse.org...
> Apparently you can't put a Table into a composite that uses a RowLayout
> *and* call setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on one of
> the controls in the composite (or a child composite, as it turns out).
>
> If I removed the TableViewer.setLayoutData call, the table appears as
> expected, and it doesn't stretch with the window, also as expected.
> However, uncommenting the setLayoutData line causes it to crash.
>
> Is this a bug or a limitation of RowLayout somehow?
>
> Thanks,
> --Michael
>
> Michael Molloy wrote:
>> One more update. I tried removing the table from it's own composite and
>> stuck it in the parent composite, but I'm still getting the same
>> exception listed below.
>>
>> Any ideas, anyone?
>>
>> Thanks,
>> --Michael
>>
>> Michael Molloy wrote:
>>
>>> Thanks for the suggestion. I may look into it, but for the time being, I
>>> would really like to get this working without introducing something else
>>> new into my code.
>>>
>>> The problem is that I can find no way to successfully call
>>> composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on the
>>> composite that contains my table.
>>>
>>> The table stretches to fill the composite it is sitting in, but that
>>> composite doesn't fill it's parent composite. Whenever I try setting the
>>> layoutData on the table's composite, I get the following error:
>>>
>>> Not a button: java.lang.ClassCastException
>>> java.lang.ClassCastException
>>>
>>> and a stacktrace.
>>>
>>> Thanks,
>>> --Michael
>>>
>>> Horst Dehmer wrote:
>>>
>>>> Hi Michael,
>>>>
Re: Table doesn't stretch to fit window--SOLVED [message #446368 is a reply to message #446356] Tue, 23 November 2004 21:34 Go to previous message
Eclipse UserFriend
Originally posted by: ukalumni.hotmail.com

My fault. I suspected it was something I was missing. Thanks very much.

--M

Veronika Irvine wrote:
> RowLayout uses RowData and GridLayout uses GridData. You can not mix the
> two together. The layout on the parent composite must match the layout data
> on the immediate children in that composite.
> If you change the layout on the parent composite to GridLayout, then you can
> use GridData.
>
> If you only have one child in the parent composite and you want the child to
> take up all of the room and be stretched you could just use FillLayout which
> requires no data.
>
> Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new GridLayout(1, false));
> final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
> Table table = tv.getTable();
> table.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> is equal to:
>
> Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new FillLayout());
> final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
>
>
> "Michael Molloy" <ukalumni@hotmail.com> wrote in message
> news:cnvik0$9h5$1@www.eclipse.org...
>
>>Apparently you can't put a Table into a composite that uses a RowLayout
>>*and* call setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on one of
>>the controls in the composite (or a child composite, as it turns out).
>>
>>If I removed the TableViewer.setLayoutData call, the table appears as
>>expected, and it doesn't stretch with the window, also as expected.
>>However, uncommenting the setLayoutData line causes it to crash.
>>
>>Is this a bug or a limitation of RowLayout somehow?
>>
>>Thanks,
>>--Michael
>>
>>Michael Molloy wrote:
>>
>>>One more update. I tried removing the table from it's own composite and
>>>stuck it in the parent composite, but I'm still getting the same
>>>exception listed below.
>>>
>>>Any ideas, anyone?
>>>
>>>Thanks,
>>>--Michael
>>>
>>>Michael Molloy wrote:
>>>
>>>
>>>>Thanks for the suggestion. I may look into it, but for the time being, I
>>>>would really like to get this working without introducing something else
>>>>new into my code.
>>>>
>>>>The problem is that I can find no way to successfully call
>>>>composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) on the
>>>>composite that contains my table.
>>>>
>>>>The table stretches to fill the composite it is sitting in, but that
>>>>composite doesn't fill it's parent composite. Whenever I try setting the
>>>>layoutData on the table's composite, I get the following error:
>>>>
>>>>Not a button: java.lang.ClassCastException
>>>>java.lang.ClassCastException
>>>>
>>>>and a stacktrace.
>>>>
>>>>Thanks,
>>>>--Michael
>>>>
>>>>Horst Dehmer wrote:
>>>>
>>>>
>>>>>Hi Michael,
>>>>>
>
>
>
Previous Topic:StylePad/Wordpad app/plugin
Next Topic:Vertical scroll bar for Text control
Goto Forum:
  


Current Time: Thu Apr 25 15:56:58 GMT 2024

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

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

Back to the top