Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Auto-resize a column?
Auto-resize a column? [message #47999] Tue, 29 January 2008 21:05 Go to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Hi,

Is there an option to have a column auto-resize to fill any gaps in the
layout of the grid (ie the user resizes the grid to bigger than the
needed column space and one column grows to this size leaving the other
columns at fixed widths) ??

Cheers,
Grant
Re: Auto-resize a column? [message #48059 is a reply to message #47999] Wed, 30 January 2008 04:10 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5227
Registered: July 2009
Senior Member
Hi,

There is discussion to provide a port from JFace-TableColumnLayout to
Grid but until now nothing happend.

Tom

Grant Slender schrieb:
> Hi,
>
> Is there an option to have a column auto-resize to fill any gaps in the
> layout of the grid (ie the user resizes the grid to bigger than the
> needed column space and one column grows to this size leaving the other
> columns at fixed widths) ??
>
> Cheers,
> Grant


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Auto-resize a column? [message #48090 is a reply to message #47999] Wed, 30 January 2008 05:13 Go to previous messageGo to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
I developed a solution - not as elegant as something inbuilt, but it
works...!!

mainGrid.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Grid g = (Grid)e.getSource();
int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
if (g.getVerticalBar().getVisible())
size -= g.getVerticalBar().getSize().x;
descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
}
});


Grant Slender wrote:
> Hi,
>
> Is there an option to have a column auto-resize to fill any gaps in the
> layout of the grid (ie the user resizes the grid to bigger than the
> needed column space and one column grows to this size leaving the other
> columns at fixed widths) ??
>
> Cheers,
> Grant
Re: Auto-resize a column? [message #48119 is a reply to message #48090] Wed, 30 January 2008 05:31 Go to previous messageGo to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Ok, my solution is not 100%

I think a bug might exist in grid - but I'm not sure??

When the grid is place inside a SashForm, and the sash is set to a %
such that the vertical scroll bar would show (ie the grid has not enough
space to show all rows) the start-up layout still shows the horizontal
scroll bar even though the resize events fired and the table columns got
reduced correctly. In fact, just touching the column width again seems
to fire the right event to realise that the horizontal scroll bar does
not need to be visible.

This behaviour does not occur when the shell is fully open - its a
problem that occurs only when building the initial displayed view.

Is this a bug in how Grid is responding to resize events before its
actually visible?

Cheers,
Grant

Grant Slender wrote:
> I developed a solution - not as elegant as something inbuilt, but it
> works...!!
>
> mainGrid.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> Grid g = (Grid)e.getSource();
> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
> if (g.getVerticalBar().getVisible())
> size -= g.getVerticalBar().getSize().x;
> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
> }
> });
>
>
> Grant Slender wrote:
>> Hi,
>>
>> Is there an option to have a column auto-resize to fill any gaps in
>> the layout of the grid (ie the user resizes the grid to bigger than
>> the needed column space and one column grows to this size leaving the
>> other columns at fixed widths) ??
>>
>> Cheers,
>> Grant
Re: Auto-resize a column? [message #48149 is a reply to message #48119] Wed, 30 January 2008 05:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5227
Registered: July 2009
Senior Member
Hi,

I don't know if using a control-adapter is the right thing. At least we
abondoned the solution for SWT-Table/SWT-Tree and use a layout-solution
(because we had massive flicker problems).

Did you tried to port the TableColumnLayout to Grid? Example can be
found at (http://wiki.eclipse.org/JFaceSnippets).

Tom

Grant Slender schrieb:
> Ok, my solution is not 100%
>
> I think a bug might exist in grid - but I'm not sure??
>
> When the grid is place inside a SashForm, and the sash is set to a %
> such that the vertical scroll bar would show (ie the grid has not enough
> space to show all rows) the start-up layout still shows the horizontal
> scroll bar even though the resize events fired and the table columns got
> reduced correctly. In fact, just touching the column width again seems
> to fire the right event to realise that the horizontal scroll bar does
> not need to be visible.
>
> This behaviour does not occur when the shell is fully open - its a
> problem that occurs only when building the initial displayed view.
>
> Is this a bug in how Grid is responding to resize events before its
> actually visible?
>
> Cheers,
> Grant
>
> Grant Slender wrote:
>> I developed a solution - not as elegant as something inbuilt, but it
>> works...!!
>>
>> mainGrid.addControlListener(new ControlAdapter() {
>> public void controlResized(ControlEvent e) {
>> Grid g = (Grid)e.getSource();
>> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
>> if (g.getVerticalBar().getVisible())
>> size -= g.getVerticalBar().getSize().x;
>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
>> }
>> });
>>
>>
>> Grant Slender wrote:
>>> Hi,
>>>
>>> Is there an option to have a column auto-resize to fill any gaps in
>>> the layout of the grid (ie the user resizes the grid to bigger than
>>> the needed column space and one column grows to this size leaving the
>>> other columns at fixed widths) ??
>>>
>>> Cheers,
>>> Grant


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Auto-resize a column? [message #48168 is a reply to message #48149] Wed, 30 January 2008 06:08 Go to previous messageGo to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Tom,

I guess porting TableColumnLayout to Grid might be the right approach,
but I'm looking for quick fix that won't take a large amount of effort.

As it turns out, I'm not getting any flicker - in fact it seems to work
fine when being controlled by the user. The only issue with my approach
is that at initial layout, when the size is determined, the code that
decides if the scroll bars should/shouldn't be shown is probably not
being called when I call setWidth on the column

Is there something I can call to programamtically make the grid check
its scroll bars properly after I setWidth on the column?

Thanks,
Grant

Tom Schindl wrote:
> Hi,
>
> I don't know if using a control-adapter is the right thing. At least we
> abondoned the solution for SWT-Table/SWT-Tree and use a layout-solution
> (because we had massive flicker problems).
>
> Did you tried to port the TableColumnLayout to Grid? Example can be
> found at (http://wiki.eclipse.org/JFaceSnippets).
>
> Tom
>
> Grant Slender schrieb:
>> Ok, my solution is not 100%
>>
>> I think a bug might exist in grid - but I'm not sure??
>>
>> When the grid is place inside a SashForm, and the sash is set to a %
>> such that the vertical scroll bar would show (ie the grid has not
>> enough space to show all rows) the start-up layout still shows the
>> horizontal scroll bar even though the resize events fired and the
>> table columns got reduced correctly. In fact, just touching the column
>> width again seems to fire the right event to realise that the
>> horizontal scroll bar does not need to be visible.
>>
>> This behaviour does not occur when the shell is fully open - its a
>> problem that occurs only when building the initial displayed view.
>>
>> Is this a bug in how Grid is responding to resize events before its
>> actually visible?
>>
>> Cheers,
>> Grant
>>
>> Grant Slender wrote:
>>> I developed a solution - not as elegant as something inbuilt, but it
>>> works...!!
>>>
>>> mainGrid.addControlListener(new ControlAdapter() {
>>> public void controlResized(ControlEvent e) {
>>> Grid g = (Grid)e.getSource();
>>> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
>>> if (g.getVerticalBar().getVisible())
>>> size -= g.getVerticalBar().getSize().x;
>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
>>> }
>>> });
>>>
>>>
>>> Grant Slender wrote:
>>>> Hi,
>>>>
>>>> Is there an option to have a column auto-resize to fill any gaps in
>>>> the layout of the grid (ie the user resizes the grid to bigger than
>>>> the needed column space and one column grows to this size leaving
>>>> the other columns at fixed widths) ??
>>>>
>>>> Cheers,
>>>> Grant
>
>
Re: Auto-resize a column? [message #48195 is a reply to message #48168] Wed, 30 January 2008 06:18 Go to previous messageGo to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
It gets even more strange....???

This fixes it - but the 6 sec delay and approach is not a solution.

I can't understand why???


Thread t = new Thread()
{
public void run()
{
try
{
Thread.sleep(6000);
descColumn.setWidth(100); // any value
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}


}
};
mainGrid.getDisplay().asyncExec(t);



Grant Slender wrote:
> Tom,
>
> I guess porting TableColumnLayout to Grid might be the right approach,
> but I'm looking for quick fix that won't take a large amount of effort.
>
> As it turns out, I'm not getting any flicker - in fact it seems to work
> fine when being controlled by the user. The only issue with my approach
> is that at initial layout, when the size is determined, the code that
> decides if the scroll bars should/shouldn't be shown is probably not
> being called when I call setWidth on the column
>
> Is there something I can call to programamtically make the grid check
> its scroll bars properly after I setWidth on the column?
>
> Thanks,
> Grant
>
> Tom Schindl wrote:
>> Hi,
>>
>> I don't know if using a control-adapter is the right thing. At least
>> we abondoned the solution for SWT-Table/SWT-Tree and use a
>> layout-solution (because we had massive flicker problems).
>>
>> Did you tried to port the TableColumnLayout to Grid? Example can be
>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>
>> Tom
>>
>> Grant Slender schrieb:
>>> Ok, my solution is not 100%
>>>
>>> I think a bug might exist in grid - but I'm not sure??
>>>
>>> When the grid is place inside a SashForm, and the sash is set to a %
>>> such that the vertical scroll bar would show (ie the grid has not
>>> enough space to show all rows) the start-up layout still shows the
>>> horizontal scroll bar even though the resize events fired and the
>>> table columns got reduced correctly. In fact, just touching the
>>> column width again seems to fire the right event to realise that the
>>> horizontal scroll bar does not need to be visible.
>>>
>>> This behaviour does not occur when the shell is fully open - its a
>>> problem that occurs only when building the initial displayed view.
>>>
>>> Is this a bug in how Grid is responding to resize events before its
>>> actually visible?
>>>
>>> Cheers,
>>> Grant
>>>
>>> Grant Slender wrote:
>>>> I developed a solution - not as elegant as something inbuilt, but it
>>>> works...!!
>>>>
>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>> public void controlResized(ControlEvent e) {
>>>> Grid g = (Grid)e.getSource();
>>>> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
>>>> if (g.getVerticalBar().getVisible())
>>>> size -= g.getVerticalBar().getSize().x;
>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
>>>> }
>>>> });
>>>>
>>>>
>>>> Grant Slender wrote:
>>>>> Hi,
>>>>>
>>>>> Is there an option to have a column auto-resize to fill any gaps in
>>>>> the layout of the grid (ie the user resizes the grid to bigger than
>>>>> the needed column space and one column grows to this size leaving
>>>>> the other columns at fixed widths) ??
>>>>>
>>>>> Cheers,
>>>>> Grant
>>
>>
Re: Auto-resize a column? [message #48225 is a reply to message #48195] Wed, 30 January 2008 06:29 Go to previous messageGo to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Adding this seems to have fixed it for good. No flicker, perfect
behaviour so far. Would still like to know why its needed.

mainGrid.getDisplay().asyncExec(new Thread() {
public void run(){
descColumn.setWidth(descColumn.getWidth());
}
});


Grant Slender wrote:
> It gets even more strange....???
>
> This fixes it - but the 6 sec delay and approach is not a solution.
>
> I can't understand why???
>
>
> Thread t = new Thread()
> {
> public void run()
> {
> try
> {
> Thread.sleep(6000);
> descColumn.setWidth(100); // any value
> }
> catch (InterruptedException e)
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> }
> };
> mainGrid.getDisplay().asyncExec(t);
>
>
>
> Grant Slender wrote:
>> Tom,
>>
>> I guess porting TableColumnLayout to Grid might be the right approach,
>> but I'm looking for quick fix that won't take a large amount of effort.
>>
>> As it turns out, I'm not getting any flicker - in fact it seems to
>> work fine when being controlled by the user. The only issue with my
>> approach is that at initial layout, when the size is determined, the
>> code that decides if the scroll bars should/shouldn't be shown is
>> probably not being called when I call setWidth on the column
>>
>> Is there something I can call to programamtically make the grid check
>> its scroll bars properly after I setWidth on the column?
>>
>> Thanks,
>> Grant
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> I don't know if using a control-adapter is the right thing. At least
>>> we abondoned the solution for SWT-Table/SWT-Tree and use a
>>> layout-solution (because we had massive flicker problems).
>>>
>>> Did you tried to port the TableColumnLayout to Grid? Example can be
>>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>>
>>> Tom
>>>
>>> Grant Slender schrieb:
>>>> Ok, my solution is not 100%
>>>>
>>>> I think a bug might exist in grid - but I'm not sure??
>>>>
>>>> When the grid is place inside a SashForm, and the sash is set to a %
>>>> such that the vertical scroll bar would show (ie the grid has not
>>>> enough space to show all rows) the start-up layout still shows the
>>>> horizontal scroll bar even though the resize events fired and the
>>>> table columns got reduced correctly. In fact, just touching the
>>>> column width again seems to fire the right event to realise that the
>>>> horizontal scroll bar does not need to be visible.
>>>>
>>>> This behaviour does not occur when the shell is fully open - its a
>>>> problem that occurs only when building the initial displayed view.
>>>>
>>>> Is this a bug in how Grid is responding to resize events before its
>>>> actually visible?
>>>>
>>>> Cheers,
>>>> Grant
>>>>
>>>> Grant Slender wrote:
>>>>> I developed a solution - not as elegant as something inbuilt, but
>>>>> it works...!!
>>>>>
>>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>>> public void controlResized(ControlEvent e) {
>>>>> Grid g = (Grid)e.getSource();
>>>>> int size = (g.getSize().x - (otherColsWidth)) -
>>>>> g.getBorderWidth()*2;
>>>>> if (g.getVerticalBar().getVisible())
>>>>> size -= g.getVerticalBar().getSize().x;
>>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth :
>>>>> size);
>>>>> }
>>>>> });
>>>>>
>>>>>
>>>>> Grant Slender wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Is there an option to have a column auto-resize to fill any gaps
>>>>>> in the layout of the grid (ie the user resizes the grid to bigger
>>>>>> than the needed column space and one column grows to this size
>>>>>> leaving the other columns at fixed widths) ??
>>>>>>
>>>>>> Cheers,
>>>>>> Grant
>>>
>>>
Re: Auto-resize a column? [message #48376 is a reply to message #48225] Fri, 01 February 2008 12:19 Go to previous messageGo to next message
Chris Gross is currently offline Chris Gross
Messages: 253
Registered: July 2009
Senior Member
Hi Grant,

The Grid does do some tricky stuff related to recalculating the
scrollbars. Can you write a quick snippet that demonstrates the problem
you're seeing? Something I can run as a test case?

Thanks,
-Chris

Grant Slender wrote:
> Adding this seems to have fixed it for good. No flicker, perfect
> behaviour so far. Would still like to know why its needed.
>
> mainGrid.getDisplay().asyncExec(new Thread() {
> public void run(){
> descColumn.setWidth(descColumn.getWidth());
> }
> });
>
>
> Grant Slender wrote:
>> It gets even more strange....???
>>
>> This fixes it - but the 6 sec delay and approach is not a solution.
>>
>> I can't understand why???
>>
>>
>> Thread t = new Thread()
>> {
>> public void run()
>> {
>> try
>> {
>> Thread.sleep(6000);
>> descColumn.setWidth(100); // any value
>> }
>> catch (InterruptedException e)
>> { // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>> };
>> mainGrid.getDisplay().asyncExec(t);
>>
>>
>>
>> Grant Slender wrote:
>>> Tom,
>>>
>>> I guess porting TableColumnLayout to Grid might be the right
>>> approach, but I'm looking for quick fix that won't take a large
>>> amount of effort.
>>>
>>> As it turns out, I'm not getting any flicker - in fact it seems to
>>> work fine when being controlled by the user. The only issue with my
>>> approach is that at initial layout, when the size is determined, the
>>> code that decides if the scroll bars should/shouldn't be shown is
>>> probably not being called when I call setWidth on the column
>>>
>>> Is there something I can call to programamtically make the grid check
>>> its scroll bars properly after I setWidth on the column?
>>>
>>> Thanks,
>>> Grant
>>>
>>> Tom Schindl wrote:
>>>> Hi,
>>>>
>>>> I don't know if using a control-adapter is the right thing. At least
>>>> we abondoned the solution for SWT-Table/SWT-Tree and use a
>>>> layout-solution (because we had massive flicker problems).
>>>>
>>>> Did you tried to port the TableColumnLayout to Grid? Example can be
>>>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>>>
>>>> Tom
>>>>
>>>> Grant Slender schrieb:
>>>>> Ok, my solution is not 100%
>>>>>
>>>>> I think a bug might exist in grid - but I'm not sure??
>>>>>
>>>>> When the grid is place inside a SashForm, and the sash is set to a
>>>>> % such that the vertical scroll bar would show (ie the grid has not
>>>>> enough space to show all rows) the start-up layout still shows the
>>>>> horizontal scroll bar even though the resize events fired and the
>>>>> table columns got reduced correctly. In fact, just touching the
>>>>> column width again seems to fire the right event to realise that
>>>>> the horizontal scroll bar does not need to be visible.
>>>>>
>>>>> This behaviour does not occur when the shell is fully open - its a
>>>>> problem that occurs only when building the initial displayed view.
>>>>>
>>>>> Is this a bug in how Grid is responding to resize events before its
>>>>> actually visible?
>>>>>
>>>>> Cheers,
>>>>> Grant
>>>>>
>>>>> Grant Slender wrote:
>>>>>> I developed a solution - not as elegant as something inbuilt, but
>>>>>> it works...!!
>>>>>>
>>>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>>>> public void controlResized(ControlEvent e) {
>>>>>> Grid g = (Grid)e.getSource();
>>>>>> int size = (g.getSize().x - (otherColsWidth)) -
>>>>>> g.getBorderWidth()*2;
>>>>>> if (g.getVerticalBar().getVisible())
>>>>>> size -= g.getVerticalBar().getSize().x;
>>>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth :
>>>>>> size);
>>>>>> }
>>>>>> });
>>>>>>
>>>>>>
>>>>>> Grant Slender wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> Is there an option to have a column auto-resize to fill any gaps
>>>>>>> in the layout of the grid (ie the user resizes the grid to bigger
>>>>>>> than the needed column space and one column grows to this size
>>>>>>> leaving the other columns at fixed widths) ??
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Grant
>>>>
>>>>
Re: Auto-resize a column? [message #48484 is a reply to message #48376] Sat, 02 February 2008 04:52 Go to previous messageGo to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Give me a day and I'll post a snippet that actually solves the problem
mostly for me, and a snippet that has the problem I identified with Grid

Cheers,
Grant


Chris Gross wrote:
> Hi Grant,
>
> The Grid does do some tricky stuff related to recalculating the
> scrollbars. Can you write a quick snippet that demonstrates the problem
> you're seeing? Something I can run as a test case?
>
> Thanks,
> -Chris
>
> Grant Slender wrote:
>> Adding this seems to have fixed it for good. No flicker, perfect
>> behaviour so far. Would still like to know why its needed.
>>
>> mainGrid.getDisplay().asyncExec(new Thread() {
>> public void run(){
>> descColumn.setWidth(descColumn.getWidth()); }
>> });
>>
>>
>> Grant Slender wrote:
>>> It gets even more strange....???
>>>
>>> This fixes it - but the 6 sec delay and approach is not a solution.
>>>
>>> I can't understand why???
>>>
>>>
>>> Thread t = new Thread()
>>> {
>>> public void run()
>>> {
>>> try
>>> {
>>> Thread.sleep(6000);
>>> descColumn.setWidth(100); // any value
>>> }
>>> catch (InterruptedException e)
>>> { // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> }
>>> };
>>> mainGrid.getDisplay().asyncExec(t);
>>>
>>>
>>>
>>> Grant Slender wrote:
>>>> Tom,
>>>>
>>>> I guess porting TableColumnLayout to Grid might be the right
>>>> approach, but I'm looking for quick fix that won't take a large
>>>> amount of effort.
>>>>
>>>> As it turns out, I'm not getting any flicker - in fact it seems to
>>>> work fine when being controlled by the user. The only issue with my
>>>> approach is that at initial layout, when the size is determined, the
>>>> code that decides if the scroll bars should/shouldn't be shown is
>>>> probably not being called when I call setWidth on the column
>>>>
>>>> Is there something I can call to programamtically make the grid
>>>> check its scroll bars properly after I setWidth on the column?
>>>>
>>>> Thanks,
>>>> Grant
>>>>
>>>> Tom Schindl wrote:
>>>>> Hi,
>>>>>
>>>>> I don't know if using a control-adapter is the right thing. At
>>>>> least we abondoned the solution for SWT-Table/SWT-Tree and use a
>>>>> layout-solution (because we had massive flicker problems).
>>>>>
>>>>> Did you tried to port the TableColumnLayout to Grid? Example can be
>>>>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>>>>
>>>>> Tom
>>>>>
>>>>> Grant Slender schrieb:
>>>>>> Ok, my solution is not 100%
>>>>>>
>>>>>> I think a bug might exist in grid - but I'm not sure??
>>>>>>
>>>>>> When the grid is place inside a SashForm, and the sash is set to a
>>>>>> % such that the vertical scroll bar would show (ie the grid has
>>>>>> not enough space to show all rows) the start-up layout still shows
>>>>>> the horizontal scroll bar even though the resize events fired and
>>>>>> the table columns got reduced correctly. In fact, just touching
>>>>>> the column width again seems to fire the right event to realise
>>>>>> that the horizontal scroll bar does not need to be visible.
>>>>>>
>>>>>> This behaviour does not occur when the shell is fully open - its a
>>>>>> problem that occurs only when building the initial displayed view.
>>>>>>
>>>>>> Is this a bug in how Grid is responding to resize events before
>>>>>> its actually visible?
>>>>>>
>>>>>> Cheers,
>>>>>> Grant
>>>>>>
>>>>>> Grant Slender wrote:
>>>>>>> I developed a solution - not as elegant as something inbuilt, but
>>>>>>> it works...!!
>>>>>>>
>>>>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>>>>> public void controlResized(ControlEvent e) {
>>>>>>> Grid g = (Grid)e.getSource();
>>>>>>> int size = (g.getSize().x - (otherColsWidth)) -
>>>>>>> g.getBorderWidth()*2;
>>>>>>> if (g.getVerticalBar().getVisible())
>>>>>>> size -= g.getVerticalBar().getSize().x;
>>>>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth :
>>>>>>> size);
>>>>>>> }
>>>>>>> });
>>>>>>>
>>>>>>>
>>>>>>> Grant Slender wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> Is there an option to have a column auto-resize to fill any gaps
>>>>>>>> in the layout of the grid (ie the user resizes the grid to
>>>>>>>> bigger than the needed column space and one column grows to this
>>>>>>>> size leaving the other columns at fixed widths) ??
>>>>>>>>
>>>>>>>> Cheers,
>>>>>>>> Grant
>>>>>
>>>>>
Re: Auto-resize a column? [message #48514 is a reply to message #48376] Sat, 02 February 2008 17:01 Go to previous messageGo to next message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------030606060903000506040800
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Included here and as an attachment...



import org.eclipse.nebula.widgets.grid.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class GridSashSnippet {

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

SashForm sashForm = new SashForm(shell,SWT.VERTICAL);
FormData formData = new FormData();
formData.top = new FormAttachment(0,0);
formData.left = new FormAttachment(0,0);
formData.right = new FormAttachment(100,0);
formData.bottom = new FormAttachment(100,0);
sashForm.setLayoutData(formData);
final int nameColumnWidth = 150;
final int descColumnWidth = 250;
final int amtColumnWidth = 100;
final int freqColumnWidth = 120;

final Grid mainGrid= new Grid(sashForm,SWT.BORDER | SWT.V_SCROLL |
SWT.H_SCROLL);
mainGrid.setHeaderVisible(true);
final GridColumn nameColumn = new GridColumn(mainGrid,SWT.NONE);
nameColumn.setText("Name");
nameColumn.setTree(true);
nameColumn.setWidth(nameColumnWidth);

final GridColumn descColumn = new GridColumn(mainGrid,SWT.NONE);
descColumn.setText("Description / Notes");

final GridColumn amtColumn = new GridColumn(mainGrid,SWT.RIGHT);
amtColumn.setText("Amount");
amtColumn.setWidth(amtColumnWidth);

final GridColumn freqColumn = new GridColumn(mainGrid,SWT.CENTER);
freqColumn.setText("Frequency");
freqColumn.setWidth(freqColumnWidth);

mainGrid.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Grid g = (Grid)e.getSource();
int othercolumns = nameColumn.getWidth() + amtColumn.getWidth() +
freqColumn.getWidth();
int size = (g.getSize().x - othercolumns) - g.getBorderWidth()*2;

if (g.getVerticalBar().getVisible()) {
size -= (g.getVerticalBar().getSize().x);
}

descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
/** without a call to update, the grid opens showing an unneeded bottom
scroll bar
* that when you move the sash up or down, will go away as it is
supposed to
* the problem is that it should open not showing the bottom scroll bar !!
* a call to update here fixes the initial open display problem
*/
// g.getDisplay().update();
}
});

//add some items to the grid
for (int bc =0; bc < 5;bc++) {
GridItem item1 = new GridItem(mainGrid,SWT.NONE);
item1.setText(0,"name"+bc);
item1.setText(1,"description"+bc);

for (int bi =0; bi < 3;bi++) {
GridItem item2 = new GridItem(item1,SWT.NONE);
item2.setText(0,"biname"+bi);
item2.setText(1,"bidescription"+bi);
item2.setText(2,bi+"");
item2.setText(3,"every day");
}

item1.setExpanded(true);
}

// add something to the lower part of the shell sashform
ScrolledComposite sc = new ScrolledComposite(sashForm,SWT.H_SCROLL |
SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(450,200);

sashForm.setWeights(new int[] {60,40});

/** in this snippet, calling pack fixes problem and doesn't require a
call to update.
* in a larger application (where the grid might be on a tabfolder or
not just on a simple shell)
* this does not fix the problem and the call to update is the only
fix above...
*/
// shell.pack ();

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



Chris Gross wrote:
> Hi Grant,
>
> The Grid does do some tricky stuff related to recalculating the
> scrollbars. Can you write a quick snippet that demonstrates the problem
> you're seeing? Something I can run as a test case?
>
> Thanks,
> -Chris
>


--------------030606060903000506040800
Content-Type: text/plain;
name="GridSashSnippet.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="GridSashSnippet.java"


import org.eclipse.nebula.widgets.grid.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class GridSashSnippet {

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

SashForm sashForm = new SashForm(shell,SWT.VERTICAL);
FormData formData = new FormData();
formData.top = new FormAttachment(0,0);
formData.left = new FormAttachment(0,0);
formData.right = new FormAttachment(100,0);
formData.bottom = new FormAttachment(100,0);
sashForm.setLayoutData(formData);
final int nameColumnWidth = 150;
final int descColumnWidth = 250;
final int amtColumnWidth = 100;
final int freqColumnWidth = 120;

final Grid mainGrid= new Grid(sashForm,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
mainGrid.setHeaderVisible(true);
final GridColumn nameColumn = new GridColumn(mainGrid,SWT.NONE);
nameColumn.setText("Name");
nameColumn.setTree(true);
nameColumn.setWidth(nameColumnWidth);

final GridColumn descColumn = new GridColumn(mainGrid,SWT.NONE);
descColumn.setText("Description / Notes");

final GridColumn amtColumn = new GridColumn(mainGrid,SWT.RIGHT);
amtColumn.setText("Amount");
amtColumn.setWidth(amtColumnWidth);

final GridColumn freqColumn = new GridColumn(mainGrid,SWT.CENTER);
freqColumn.setText("Frequency");
freqColumn.setWidth(freqColumnWidth);

mainGrid.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Grid g = (Grid)e.getSource();
int othercolumns = nameColumn.getWidth() + amtColumn.getWidth() + freqColumn.getWidth();
int size = (g.getSize().x - othercolumns) - g.getBorderWidth()*2;

if (g.getVerticalBar().getVisible()) {
size -= (g.getVerticalBar().getSize().x);
}

descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
/** without a call to update, the grid opens showing an unneeded bottom scroll bar
* that when you move the sash up or down, will go away as it is supposed to
* the problem is that it should open not showing the bottom scroll bar !!
* a call to update here fixes the initial open display problem
*/
// g.getDisplay().update();
}
});

//add some items to the grid
for (int bc =0; bc < 5;bc++) {
GridItem item1 = new GridItem(mainGrid,SWT.NONE);
item1.setText(0,"name"+bc);
item1.setText(1,"description"+bc);

for (int bi =0; bi < 3;bi++) {
GridItem item2 = new GridItem(item1,SWT.NONE);
item2.setText(0,"biname"+bi);
item2.setText(1,"bidescription"+bi);
item2.setText(2,bi+"");
item2.setText(3,"every day");
}

item1.setExpanded(true);
}

// add something to the lower part of the shell sashform
ScrolledComposite sc = new ScrolledComposite(sashForm,SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(450,200);

sashForm.setWeights(new int[] {60,40});

/** in this snippet, calling pack fixes problem and doesn't require a call to update.
* in a larger application (where the grid might be on a tabfolder or not just on a simple shell)
* this does not fix the problem and the call to update is the only fix above...
*/
// shell.pack ();

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

--------------030606060903000506040800--
Re: Auto-resize a column? [message #50054 is a reply to message #48514] Wed, 27 February 2008 10:59 Go to previous message
Chris Gross is currently offline Chris Gross
Messages: 253
Registered: July 2009
Senior Member
This is really confusing me. The Grid code seems correct but the events
are getting fired strangely. As far as I can tell the resize event is
getting processed _during_ the paint event?! Its almost as if there are
multiple threads going on here but there should not be.

Regardless, adding Display.update will trigger a new paint event and as
you've seen causes a recalculation of the scrollbars. There's no harm
in that update() call.

regards,
-Chris

Grant Slender wrote:
> Included here and as an attachment...
>
>
>
> import org.eclipse.nebula.widgets.grid.*;
> import org.eclipse.swt.*;
> import org.eclipse.swt.custom.*;
> import org.eclipse.swt.events.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
>
> public class GridSashSnippet {
>
> public static void main(String[] args) {
> final Display display = new Display ();
> final Shell shell = new Shell (display);
> shell.setLayout(new FormLayout());
>
> SashForm sashForm = new SashForm(shell,SWT.VERTICAL);
> FormData formData = new FormData();
> formData.top = new FormAttachment(0,0);
> formData.left = new FormAttachment(0,0);
> formData.right = new FormAttachment(100,0);
> formData.bottom = new FormAttachment(100,0);
> sashForm.setLayoutData(formData);
> final int nameColumnWidth = 150;
> final int descColumnWidth = 250;
> final int amtColumnWidth = 100;
> final int freqColumnWidth = 120;
>
> final Grid mainGrid= new Grid(sashForm,SWT.BORDER | SWT.V_SCROLL
> | SWT.H_SCROLL);
> mainGrid.setHeaderVisible(true);
> final GridColumn nameColumn = new GridColumn(mainGrid,SWT.NONE);
> nameColumn.setText("Name");
> nameColumn.setTree(true);
> nameColumn.setWidth(nameColumnWidth);
>
> final GridColumn descColumn = new GridColumn(mainGrid,SWT.NONE);
> descColumn.setText("Description / Notes");
>
> final GridColumn amtColumn = new GridColumn(mainGrid,SWT.RIGHT);
> amtColumn.setText("Amount");
> amtColumn.setWidth(amtColumnWidth);
>
> final GridColumn freqColumn = new GridColumn(mainGrid,SWT.CENTER);
> freqColumn.setText("Frequency");
> freqColumn.setWidth(freqColumnWidth);
>
> mainGrid.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> Grid g = (Grid)e.getSource();
> int othercolumns = nameColumn.getWidth() +
> amtColumn.getWidth() + freqColumn.getWidth();
> int size = (g.getSize().x - othercolumns) -
> g.getBorderWidth()*2;
>
> if (g.getVerticalBar().getVisible()) {
> size -= (g.getVerticalBar().getSize().x);
> }
>
> descColumn.setWidth(size < descColumnWidth ?
> descColumnWidth : size);
> /** without a call to update, the grid opens showing an unneeded
> bottom scroll bar
> * that when you move the sash up or down, will go away as it is
> supposed to
> * the problem is that it should open not showing the bottom scroll
> bar !!
> * a call to update here fixes the initial open display problem
> */
> // g.getDisplay().update();
> }
> });
>
> //add some items to the grid
> for (int bc =0; bc < 5;bc++) {
> GridItem item1 = new GridItem(mainGrid,SWT.NONE);
> item1.setText(0,"name"+bc);
> item1.setText(1,"description"+bc);
>
> for (int bi =0; bi < 3;bi++) {
> GridItem item2 = new GridItem(item1,SWT.NONE);
> item2.setText(0,"biname"+bi);
> item2.setText(1,"bidescription"+bi);
> item2.setText(2,bi+"");
> item2.setText(3,"every day");
> }
>
> item1.setExpanded(true);
> }
>
> // add something to the lower part of the shell sashform
> ScrolledComposite sc = new
> ScrolledComposite(sashForm,SWT.H_SCROLL | SWT.V_SCROLL);
> sc.setExpandHorizontal(true);
> sc.setExpandVertical(true);
> sc.setMinSize(450,200);
>
> sashForm.setWeights(new int[] {60,40});
>
> /** in this snippet, calling pack fixes problem and doesn't require
> a call to update.
> * in a larger application (where the grid might be on a tabfolder
> or not just on a simple shell)
> * this does not fix the problem and the call to update is the only
> fix above...
> */
> // shell.pack ();
>
> shell.open ();
> shell.setSize(700,600);
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
> }
>
>
>
> Chris Gross wrote:
>> Hi Grant,
>>
>> The Grid does do some tricky stuff related to recalculating the
>> scrollbars. Can you write a quick snippet that demonstrates the
>> problem you're seeing? Something I can run as a test case?
>>
>> Thanks,
>> -Chris
>>
>
Re: Auto-resize a column? [message #588156 is a reply to message #47999] Wed, 30 January 2008 04:10 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5227
Registered: July 2009
Senior Member
Hi,

There is discussion to provide a port from JFace-TableColumnLayout to
Grid but until now nothing happend.

Tom

Grant Slender schrieb:
> Hi,
>
> Is there an option to have a column auto-resize to fill any gaps in the
> layout of the grid (ie the user resizes the grid to bigger than the
> needed column space and one column grows to this size leaving the other
> columns at fixed widths) ??
>
> Cheers,
> Grant


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Auto-resize a column? [message #588162 is a reply to message #47999] Wed, 30 January 2008 05:13 Go to previous message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
I developed a solution - not as elegant as something inbuilt, but it
works...!!

mainGrid.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Grid g = (Grid)e.getSource();
int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
if (g.getVerticalBar().getVisible())
size -= g.getVerticalBar().getSize().x;
descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
}
});


Grant Slender wrote:
> Hi,
>
> Is there an option to have a column auto-resize to fill any gaps in the
> layout of the grid (ie the user resizes the grid to bigger than the
> needed column space and one column grows to this size leaving the other
> columns at fixed widths) ??
>
> Cheers,
> Grant
Re: Auto-resize a column? [message #588171 is a reply to message #48090] Wed, 30 January 2008 05:31 Go to previous message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Ok, my solution is not 100%

I think a bug might exist in grid - but I'm not sure??

When the grid is place inside a SashForm, and the sash is set to a %
such that the vertical scroll bar would show (ie the grid has not enough
space to show all rows) the start-up layout still shows the horizontal
scroll bar even though the resize events fired and the table columns got
reduced correctly. In fact, just touching the column width again seems
to fire the right event to realise that the horizontal scroll bar does
not need to be visible.

This behaviour does not occur when the shell is fully open - its a
problem that occurs only when building the initial displayed view.

Is this a bug in how Grid is responding to resize events before its
actually visible?

Cheers,
Grant

Grant Slender wrote:
> I developed a solution - not as elegant as something inbuilt, but it
> works...!!
>
> mainGrid.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> Grid g = (Grid)e.getSource();
> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
> if (g.getVerticalBar().getVisible())
> size -= g.getVerticalBar().getSize().x;
> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
> }
> });
>
>
> Grant Slender wrote:
>> Hi,
>>
>> Is there an option to have a column auto-resize to fill any gaps in
>> the layout of the grid (ie the user resizes the grid to bigger than
>> the needed column space and one column grows to this size leaving the
>> other columns at fixed widths) ??
>>
>> Cheers,
>> Grant
Re: Auto-resize a column? [message #588181 is a reply to message #48119] Wed, 30 January 2008 05:38 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5227
Registered: July 2009
Senior Member
Hi,

I don't know if using a control-adapter is the right thing. At least we
abondoned the solution for SWT-Table/SWT-Tree and use a layout-solution
(because we had massive flicker problems).

Did you tried to port the TableColumnLayout to Grid? Example can be
found at (http://wiki.eclipse.org/JFaceSnippets).

Tom

Grant Slender schrieb:
> Ok, my solution is not 100%
>
> I think a bug might exist in grid - but I'm not sure??
>
> When the grid is place inside a SashForm, and the sash is set to a %
> such that the vertical scroll bar would show (ie the grid has not enough
> space to show all rows) the start-up layout still shows the horizontal
> scroll bar even though the resize events fired and the table columns got
> reduced correctly. In fact, just touching the column width again seems
> to fire the right event to realise that the horizontal scroll bar does
> not need to be visible.
>
> This behaviour does not occur when the shell is fully open - its a
> problem that occurs only when building the initial displayed view.
>
> Is this a bug in how Grid is responding to resize events before its
> actually visible?
>
> Cheers,
> Grant
>
> Grant Slender wrote:
>> I developed a solution - not as elegant as something inbuilt, but it
>> works...!!
>>
>> mainGrid.addControlListener(new ControlAdapter() {
>> public void controlResized(ControlEvent e) {
>> Grid g = (Grid)e.getSource();
>> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
>> if (g.getVerticalBar().getVisible())
>> size -= g.getVerticalBar().getSize().x;
>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
>> }
>> });
>>
>>
>> Grant Slender wrote:
>>> Hi,
>>>
>>> Is there an option to have a column auto-resize to fill any gaps in
>>> the layout of the grid (ie the user resizes the grid to bigger than
>>> the needed column space and one column grows to this size leaving the
>>> other columns at fixed widths) ??
>>>
>>> Cheers,
>>> Grant


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Auto-resize a column? [message #588185 is a reply to message #48149] Wed, 30 January 2008 06:08 Go to previous message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Tom,

I guess porting TableColumnLayout to Grid might be the right approach,
but I'm looking for quick fix that won't take a large amount of effort.

As it turns out, I'm not getting any flicker - in fact it seems to work
fine when being controlled by the user. The only issue with my approach
is that at initial layout, when the size is determined, the code that
decides if the scroll bars should/shouldn't be shown is probably not
being called when I call setWidth on the column

Is there something I can call to programamtically make the grid check
its scroll bars properly after I setWidth on the column?

Thanks,
Grant

Tom Schindl wrote:
> Hi,
>
> I don't know if using a control-adapter is the right thing. At least we
> abondoned the solution for SWT-Table/SWT-Tree and use a layout-solution
> (because we had massive flicker problems).
>
> Did you tried to port the TableColumnLayout to Grid? Example can be
> found at (http://wiki.eclipse.org/JFaceSnippets).
>
> Tom
>
> Grant Slender schrieb:
>> Ok, my solution is not 100%
>>
>> I think a bug might exist in grid - but I'm not sure??
>>
>> When the grid is place inside a SashForm, and the sash is set to a %
>> such that the vertical scroll bar would show (ie the grid has not
>> enough space to show all rows) the start-up layout still shows the
>> horizontal scroll bar even though the resize events fired and the
>> table columns got reduced correctly. In fact, just touching the column
>> width again seems to fire the right event to realise that the
>> horizontal scroll bar does not need to be visible.
>>
>> This behaviour does not occur when the shell is fully open - its a
>> problem that occurs only when building the initial displayed view.
>>
>> Is this a bug in how Grid is responding to resize events before its
>> actually visible?
>>
>> Cheers,
>> Grant
>>
>> Grant Slender wrote:
>>> I developed a solution - not as elegant as something inbuilt, but it
>>> works...!!
>>>
>>> mainGrid.addControlListener(new ControlAdapter() {
>>> public void controlResized(ControlEvent e) {
>>> Grid g = (Grid)e.getSource();
>>> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
>>> if (g.getVerticalBar().getVisible())
>>> size -= g.getVerticalBar().getSize().x;
>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
>>> }
>>> });
>>>
>>>
>>> Grant Slender wrote:
>>>> Hi,
>>>>
>>>> Is there an option to have a column auto-resize to fill any gaps in
>>>> the layout of the grid (ie the user resizes the grid to bigger than
>>>> the needed column space and one column grows to this size leaving
>>>> the other columns at fixed widths) ??
>>>>
>>>> Cheers,
>>>> Grant
>
>
Re: Auto-resize a column? [message #588195 is a reply to message #48168] Wed, 30 January 2008 06:18 Go to previous message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
It gets even more strange....???

This fixes it - but the 6 sec delay and approach is not a solution.

I can't understand why???


Thread t = new Thread()
{
public void run()
{
try
{
Thread.sleep(6000);
descColumn.setWidth(100); // any value
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}


}
};
mainGrid.getDisplay().asyncExec(t);



Grant Slender wrote:
> Tom,
>
> I guess porting TableColumnLayout to Grid might be the right approach,
> but I'm looking for quick fix that won't take a large amount of effort.
>
> As it turns out, I'm not getting any flicker - in fact it seems to work
> fine when being controlled by the user. The only issue with my approach
> is that at initial layout, when the size is determined, the code that
> decides if the scroll bars should/shouldn't be shown is probably not
> being called when I call setWidth on the column
>
> Is there something I can call to programamtically make the grid check
> its scroll bars properly after I setWidth on the column?
>
> Thanks,
> Grant
>
> Tom Schindl wrote:
>> Hi,
>>
>> I don't know if using a control-adapter is the right thing. At least
>> we abondoned the solution for SWT-Table/SWT-Tree and use a
>> layout-solution (because we had massive flicker problems).
>>
>> Did you tried to port the TableColumnLayout to Grid? Example can be
>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>
>> Tom
>>
>> Grant Slender schrieb:
>>> Ok, my solution is not 100%
>>>
>>> I think a bug might exist in grid - but I'm not sure??
>>>
>>> When the grid is place inside a SashForm, and the sash is set to a %
>>> such that the vertical scroll bar would show (ie the grid has not
>>> enough space to show all rows) the start-up layout still shows the
>>> horizontal scroll bar even though the resize events fired and the
>>> table columns got reduced correctly. In fact, just touching the
>>> column width again seems to fire the right event to realise that the
>>> horizontal scroll bar does not need to be visible.
>>>
>>> This behaviour does not occur when the shell is fully open - its a
>>> problem that occurs only when building the initial displayed view.
>>>
>>> Is this a bug in how Grid is responding to resize events before its
>>> actually visible?
>>>
>>> Cheers,
>>> Grant
>>>
>>> Grant Slender wrote:
>>>> I developed a solution - not as elegant as something inbuilt, but it
>>>> works...!!
>>>>
>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>> public void controlResized(ControlEvent e) {
>>>> Grid g = (Grid)e.getSource();
>>>> int size = (g.getSize().x - (otherColsWidth)) - g.getBorderWidth()*2;
>>>> if (g.getVerticalBar().getVisible())
>>>> size -= g.getVerticalBar().getSize().x;
>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
>>>> }
>>>> });
>>>>
>>>>
>>>> Grant Slender wrote:
>>>>> Hi,
>>>>>
>>>>> Is there an option to have a column auto-resize to fill any gaps in
>>>>> the layout of the grid (ie the user resizes the grid to bigger than
>>>>> the needed column space and one column grows to this size leaving
>>>>> the other columns at fixed widths) ??
>>>>>
>>>>> Cheers,
>>>>> Grant
>>
>>
Re: Auto-resize a column? [message #588203 is a reply to message #48195] Wed, 30 January 2008 06:29 Go to previous message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Adding this seems to have fixed it for good. No flicker, perfect
behaviour so far. Would still like to know why its needed.

mainGrid.getDisplay().asyncExec(new Thread() {
public void run(){
descColumn.setWidth(descColumn.getWidth());
}
});


Grant Slender wrote:
> It gets even more strange....???
>
> This fixes it - but the 6 sec delay and approach is not a solution.
>
> I can't understand why???
>
>
> Thread t = new Thread()
> {
> public void run()
> {
> try
> {
> Thread.sleep(6000);
> descColumn.setWidth(100); // any value
> }
> catch (InterruptedException e)
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> }
> };
> mainGrid.getDisplay().asyncExec(t);
>
>
>
> Grant Slender wrote:
>> Tom,
>>
>> I guess porting TableColumnLayout to Grid might be the right approach,
>> but I'm looking for quick fix that won't take a large amount of effort.
>>
>> As it turns out, I'm not getting any flicker - in fact it seems to
>> work fine when being controlled by the user. The only issue with my
>> approach is that at initial layout, when the size is determined, the
>> code that decides if the scroll bars should/shouldn't be shown is
>> probably not being called when I call setWidth on the column
>>
>> Is there something I can call to programamtically make the grid check
>> its scroll bars properly after I setWidth on the column?
>>
>> Thanks,
>> Grant
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> I don't know if using a control-adapter is the right thing. At least
>>> we abondoned the solution for SWT-Table/SWT-Tree and use a
>>> layout-solution (because we had massive flicker problems).
>>>
>>> Did you tried to port the TableColumnLayout to Grid? Example can be
>>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>>
>>> Tom
>>>
>>> Grant Slender schrieb:
>>>> Ok, my solution is not 100%
>>>>
>>>> I think a bug might exist in grid - but I'm not sure??
>>>>
>>>> When the grid is place inside a SashForm, and the sash is set to a %
>>>> such that the vertical scroll bar would show (ie the grid has not
>>>> enough space to show all rows) the start-up layout still shows the
>>>> horizontal scroll bar even though the resize events fired and the
>>>> table columns got reduced correctly. In fact, just touching the
>>>> column width again seems to fire the right event to realise that the
>>>> horizontal scroll bar does not need to be visible.
>>>>
>>>> This behaviour does not occur when the shell is fully open - its a
>>>> problem that occurs only when building the initial displayed view.
>>>>
>>>> Is this a bug in how Grid is responding to resize events before its
>>>> actually visible?
>>>>
>>>> Cheers,
>>>> Grant
>>>>
>>>> Grant Slender wrote:
>>>>> I developed a solution - not as elegant as something inbuilt, but
>>>>> it works...!!
>>>>>
>>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>>> public void controlResized(ControlEvent e) {
>>>>> Grid g = (Grid)e.getSource();
>>>>> int size = (g.getSize().x - (otherColsWidth)) -
>>>>> g.getBorderWidth()*2;
>>>>> if (g.getVerticalBar().getVisible())
>>>>> size -= g.getVerticalBar().getSize().x;
>>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth :
>>>>> size);
>>>>> }
>>>>> });
>>>>>
>>>>>
>>>>> Grant Slender wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Is there an option to have a column auto-resize to fill any gaps
>>>>>> in the layout of the grid (ie the user resizes the grid to bigger
>>>>>> than the needed column space and one column grows to this size
>>>>>> leaving the other columns at fixed widths) ??
>>>>>>
>>>>>> Cheers,
>>>>>> Grant
>>>
>>>
Re: Auto-resize a column? [message #588249 is a reply to message #48225] Fri, 01 February 2008 12:19 Go to previous message
Chris Gross is currently offline Chris Gross
Messages: 471
Registered: July 2009
Senior Member
Hi Grant,

The Grid does do some tricky stuff related to recalculating the
scrollbars. Can you write a quick snippet that demonstrates the problem
you're seeing? Something I can run as a test case?

Thanks,
-Chris

Grant Slender wrote:
> Adding this seems to have fixed it for good. No flicker, perfect
> behaviour so far. Would still like to know why its needed.
>
> mainGrid.getDisplay().asyncExec(new Thread() {
> public void run(){
> descColumn.setWidth(descColumn.getWidth());
> }
> });
>
>
> Grant Slender wrote:
>> It gets even more strange....???
>>
>> This fixes it - but the 6 sec delay and approach is not a solution.
>>
>> I can't understand why???
>>
>>
>> Thread t = new Thread()
>> {
>> public void run()
>> {
>> try
>> {
>> Thread.sleep(6000);
>> descColumn.setWidth(100); // any value
>> }
>> catch (InterruptedException e)
>> { // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>> };
>> mainGrid.getDisplay().asyncExec(t);
>>
>>
>>
>> Grant Slender wrote:
>>> Tom,
>>>
>>> I guess porting TableColumnLayout to Grid might be the right
>>> approach, but I'm looking for quick fix that won't take a large
>>> amount of effort.
>>>
>>> As it turns out, I'm not getting any flicker - in fact it seems to
>>> work fine when being controlled by the user. The only issue with my
>>> approach is that at initial layout, when the size is determined, the
>>> code that decides if the scroll bars should/shouldn't be shown is
>>> probably not being called when I call setWidth on the column
>>>
>>> Is there something I can call to programamtically make the grid check
>>> its scroll bars properly after I setWidth on the column?
>>>
>>> Thanks,
>>> Grant
>>>
>>> Tom Schindl wrote:
>>>> Hi,
>>>>
>>>> I don't know if using a control-adapter is the right thing. At least
>>>> we abondoned the solution for SWT-Table/SWT-Tree and use a
>>>> layout-solution (because we had massive flicker problems).
>>>>
>>>> Did you tried to port the TableColumnLayout to Grid? Example can be
>>>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>>>
>>>> Tom
>>>>
>>>> Grant Slender schrieb:
>>>>> Ok, my solution is not 100%
>>>>>
>>>>> I think a bug might exist in grid - but I'm not sure??
>>>>>
>>>>> When the grid is place inside a SashForm, and the sash is set to a
>>>>> % such that the vertical scroll bar would show (ie the grid has not
>>>>> enough space to show all rows) the start-up layout still shows the
>>>>> horizontal scroll bar even though the resize events fired and the
>>>>> table columns got reduced correctly. In fact, just touching the
>>>>> column width again seems to fire the right event to realise that
>>>>> the horizontal scroll bar does not need to be visible.
>>>>>
>>>>> This behaviour does not occur when the shell is fully open - its a
>>>>> problem that occurs only when building the initial displayed view.
>>>>>
>>>>> Is this a bug in how Grid is responding to resize events before its
>>>>> actually visible?
>>>>>
>>>>> Cheers,
>>>>> Grant
>>>>>
>>>>> Grant Slender wrote:
>>>>>> I developed a solution - not as elegant as something inbuilt, but
>>>>>> it works...!!
>>>>>>
>>>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>>>> public void controlResized(ControlEvent e) {
>>>>>> Grid g = (Grid)e.getSource();
>>>>>> int size = (g.getSize().x - (otherColsWidth)) -
>>>>>> g.getBorderWidth()*2;
>>>>>> if (g.getVerticalBar().getVisible())
>>>>>> size -= g.getVerticalBar().getSize().x;
>>>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth :
>>>>>> size);
>>>>>> }
>>>>>> });
>>>>>>
>>>>>>
>>>>>> Grant Slender wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> Is there an option to have a column auto-resize to fill any gaps
>>>>>>> in the layout of the grid (ie the user resizes the grid to bigger
>>>>>>> than the needed column space and one column grows to this size
>>>>>>> leaving the other columns at fixed widths) ??
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Grant
>>>>
>>>>
Re: Auto-resize a column? [message #588293 is a reply to message #48376] Sat, 02 February 2008 04:52 Go to previous message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
Give me a day and I'll post a snippet that actually solves the problem
mostly for me, and a snippet that has the problem I identified with Grid

Cheers,
Grant


Chris Gross wrote:
> Hi Grant,
>
> The Grid does do some tricky stuff related to recalculating the
> scrollbars. Can you write a quick snippet that demonstrates the problem
> you're seeing? Something I can run as a test case?
>
> Thanks,
> -Chris
>
> Grant Slender wrote:
>> Adding this seems to have fixed it for good. No flicker, perfect
>> behaviour so far. Would still like to know why its needed.
>>
>> mainGrid.getDisplay().asyncExec(new Thread() {
>> public void run(){
>> descColumn.setWidth(descColumn.getWidth()); }
>> });
>>
>>
>> Grant Slender wrote:
>>> It gets even more strange....???
>>>
>>> This fixes it - but the 6 sec delay and approach is not a solution.
>>>
>>> I can't understand why???
>>>
>>>
>>> Thread t = new Thread()
>>> {
>>> public void run()
>>> {
>>> try
>>> {
>>> Thread.sleep(6000);
>>> descColumn.setWidth(100); // any value
>>> }
>>> catch (InterruptedException e)
>>> { // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> }
>>> };
>>> mainGrid.getDisplay().asyncExec(t);
>>>
>>>
>>>
>>> Grant Slender wrote:
>>>> Tom,
>>>>
>>>> I guess porting TableColumnLayout to Grid might be the right
>>>> approach, but I'm looking for quick fix that won't take a large
>>>> amount of effort.
>>>>
>>>> As it turns out, I'm not getting any flicker - in fact it seems to
>>>> work fine when being controlled by the user. The only issue with my
>>>> approach is that at initial layout, when the size is determined, the
>>>> code that decides if the scroll bars should/shouldn't be shown is
>>>> probably not being called when I call setWidth on the column
>>>>
>>>> Is there something I can call to programamtically make the grid
>>>> check its scroll bars properly after I setWidth on the column?
>>>>
>>>> Thanks,
>>>> Grant
>>>>
>>>> Tom Schindl wrote:
>>>>> Hi,
>>>>>
>>>>> I don't know if using a control-adapter is the right thing. At
>>>>> least we abondoned the solution for SWT-Table/SWT-Tree and use a
>>>>> layout-solution (because we had massive flicker problems).
>>>>>
>>>>> Did you tried to port the TableColumnLayout to Grid? Example can be
>>>>> found at (http://wiki.eclipse.org/JFaceSnippets).
>>>>>
>>>>> Tom
>>>>>
>>>>> Grant Slender schrieb:
>>>>>> Ok, my solution is not 100%
>>>>>>
>>>>>> I think a bug might exist in grid - but I'm not sure??
>>>>>>
>>>>>> When the grid is place inside a SashForm, and the sash is set to a
>>>>>> % such that the vertical scroll bar would show (ie the grid has
>>>>>> not enough space to show all rows) the start-up layout still shows
>>>>>> the horizontal scroll bar even though the resize events fired and
>>>>>> the table columns got reduced correctly. In fact, just touching
>>>>>> the column width again seems to fire the right event to realise
>>>>>> that the horizontal scroll bar does not need to be visible.
>>>>>>
>>>>>> This behaviour does not occur when the shell is fully open - its a
>>>>>> problem that occurs only when building the initial displayed view.
>>>>>>
>>>>>> Is this a bug in how Grid is responding to resize events before
>>>>>> its actually visible?
>>>>>>
>>>>>> Cheers,
>>>>>> Grant
>>>>>>
>>>>>> Grant Slender wrote:
>>>>>>> I developed a solution - not as elegant as something inbuilt, but
>>>>>>> it works...!!
>>>>>>>
>>>>>>> mainGrid.addControlListener(new ControlAdapter() {
>>>>>>> public void controlResized(ControlEvent e) {
>>>>>>> Grid g = (Grid)e.getSource();
>>>>>>> int size = (g.getSize().x - (otherColsWidth)) -
>>>>>>> g.getBorderWidth()*2;
>>>>>>> if (g.getVerticalBar().getVisible())
>>>>>>> size -= g.getVerticalBar().getSize().x;
>>>>>>> descColumn.setWidth(size < descColumnWidth ? descColumnWidth :
>>>>>>> size);
>>>>>>> }
>>>>>>> });
>>>>>>>
>>>>>>>
>>>>>>> Grant Slender wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> Is there an option to have a column auto-resize to fill any gaps
>>>>>>>> in the layout of the grid (ie the user resizes the grid to
>>>>>>>> bigger than the needed column space and one column grows to this
>>>>>>>> size leaving the other columns at fixed widths) ??
>>>>>>>>
>>>>>>>> Cheers,
>>>>>>>> Grant
>>>>>
>>>>>
Re: Auto-resize a column? [message #588301 is a reply to message #48376] Sat, 02 February 2008 17:01 Go to previous message
Grant Slender is currently offline Grant Slender
Messages: 36
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------030606060903000506040800
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Included here and as an attachment...



import org.eclipse.nebula.widgets.grid.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class GridSashSnippet {

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

SashForm sashForm = new SashForm(shell,SWT.VERTICAL);
FormData formData = new FormData();
formData.top = new FormAttachment(0,0);
formData.left = new FormAttachment(0,0);
formData.right = new FormAttachment(100,0);
formData.bottom = new FormAttachment(100,0);
sashForm.setLayoutData(formData);
final int nameColumnWidth = 150;
final int descColumnWidth = 250;
final int amtColumnWidth = 100;
final int freqColumnWidth = 120;

final Grid mainGrid= new Grid(sashForm,SWT.BORDER | SWT.V_SCROLL |
SWT.H_SCROLL);
mainGrid.setHeaderVisible(true);
final GridColumn nameColumn = new GridColumn(mainGrid,SWT.NONE);
nameColumn.setText("Name");
nameColumn.setTree(true);
nameColumn.setWidth(nameColumnWidth);

final GridColumn descColumn = new GridColumn(mainGrid,SWT.NONE);
descColumn.setText("Description / Notes");

final GridColumn amtColumn = new GridColumn(mainGrid,SWT.RIGHT);
amtColumn.setText("Amount");
amtColumn.setWidth(amtColumnWidth);

final GridColumn freqColumn = new GridColumn(mainGrid,SWT.CENTER);
freqColumn.setText("Frequency");
freqColumn.setWidth(freqColumnWidth);

mainGrid.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Grid g = (Grid)e.getSource();
int othercolumns = nameColumn.getWidth() + amtColumn.getWidth() +
freqColumn.getWidth();
int size = (g.getSize().x - othercolumns) - g.getBorderWidth()*2;

if (g.getVerticalBar().getVisible()) {
size -= (g.getVerticalBar().getSize().x);
}

descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
/** without a call to update, the grid opens showing an unneeded bottom
scroll bar
* that when you move the sash up or down, will go away as it is
supposed to
* the problem is that it should open not showing the bottom scroll bar !!
* a call to update here fixes the initial open display problem
*/
// g.getDisplay().update();
}
});

//add some items to the grid
for (int bc =0; bc < 5;bc++) {
GridItem item1 = new GridItem(mainGrid,SWT.NONE);
item1.setText(0,"name"+bc);
item1.setText(1,"description"+bc);

for (int bi =0; bi < 3;bi++) {
GridItem item2 = new GridItem(item1,SWT.NONE);
item2.setText(0,"biname"+bi);
item2.setText(1,"bidescription"+bi);
item2.setText(2,bi+"");
item2.setText(3,"every day");
}

item1.setExpanded(true);
}

// add something to the lower part of the shell sashform
ScrolledComposite sc = new ScrolledComposite(sashForm,SWT.H_SCROLL |
SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(450,200);

sashForm.setWeights(new int[] {60,40});

/** in this snippet, calling pack fixes problem and doesn't require a
call to update.
* in a larger application (where the grid might be on a tabfolder or
not just on a simple shell)
* this does not fix the problem and the call to update is the only
fix above...
*/
// shell.pack ();

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



Chris Gross wrote:
> Hi Grant,
>
> The Grid does do some tricky stuff related to recalculating the
> scrollbars. Can you write a quick snippet that demonstrates the problem
> you're seeing? Something I can run as a test case?
>
> Thanks,
> -Chris
>


--------------030606060903000506040800
Content-Type: text/plain;
name="GridSashSnippet.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="GridSashSnippet.java"


import org.eclipse.nebula.widgets.grid.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class GridSashSnippet {

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

SashForm sashForm = new SashForm(shell,SWT.VERTICAL);
FormData formData = new FormData();
formData.top = new FormAttachment(0,0);
formData.left = new FormAttachment(0,0);
formData.right = new FormAttachment(100,0);
formData.bottom = new FormAttachment(100,0);
sashForm.setLayoutData(formData);
final int nameColumnWidth = 150;
final int descColumnWidth = 250;
final int amtColumnWidth = 100;
final int freqColumnWidth = 120;

final Grid mainGrid= new Grid(sashForm,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
mainGrid.setHeaderVisible(true);
final GridColumn nameColumn = new GridColumn(mainGrid,SWT.NONE);
nameColumn.setText("Name");
nameColumn.setTree(true);
nameColumn.setWidth(nameColumnWidth);

final GridColumn descColumn = new GridColumn(mainGrid,SWT.NONE);
descColumn.setText("Description / Notes");

final GridColumn amtColumn = new GridColumn(mainGrid,SWT.RIGHT);
amtColumn.setText("Amount");
amtColumn.setWidth(amtColumnWidth);

final GridColumn freqColumn = new GridColumn(mainGrid,SWT.CENTER);
freqColumn.setText("Frequency");
freqColumn.setWidth(freqColumnWidth);

mainGrid.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Grid g = (Grid)e.getSource();
int othercolumns = nameColumn.getWidth() + amtColumn.getWidth() + freqColumn.getWidth();
int size = (g.getSize().x - othercolumns) - g.getBorderWidth()*2;

if (g.getVerticalBar().getVisible()) {
size -= (g.getVerticalBar().getSize().x);
}

descColumn.setWidth(size < descColumnWidth ? descColumnWidth : size);
/** without a call to update, the grid opens showing an unneeded bottom scroll bar
* that when you move the sash up or down, will go away as it is supposed to
* the problem is that it should open not showing the bottom scroll bar !!
* a call to update here fixes the initial open display problem
*/
// g.getDisplay().update();
}
});

//add some items to the grid
for (int bc =0; bc < 5;bc++) {
GridItem item1 = new GridItem(mainGrid,SWT.NONE);
item1.setText(0,"name"+bc);
item1.setText(1,"description"+bc);

for (int bi =0; bi < 3;bi++) {
GridItem item2 = new GridItem(item1,SWT.NONE);
item2.setText(0,"biname"+bi);
item2.setText(1,"bidescription"+bi);
item2.setText(2,bi+"");
item2.setText(3,"every day");
}

item1.setExpanded(true);
}

// add something to the lower part of the shell sashform
ScrolledComposite sc = new ScrolledComposite(sashForm,SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(450,200);

sashForm.setWeights(new int[] {60,40});

/** in this snippet, calling pack fixes problem and doesn't require a call to update.
* in a larger application (where the grid might be on a tabfolder or not just on a simple shell)
* this does not fix the problem and the call to update is the only fix above...
*/
// shell.pack ();

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

--------------030606060903000506040800--
Re: Auto-resize a column? [message #588808 is a reply to message #48514] Wed, 27 February 2008 10:59 Go to previous message
Chris Gross is currently offline Chris Gross
Messages: 471
Registered: July 2009
Senior Member
This is really confusing me. The Grid code seems correct but the events
are getting fired strangely. As far as I can tell the resize event is
getting processed _during_ the paint event?! Its almost as if there are
multiple threads going on here but there should not be.

Regardless, adding Display.update will trigger a new paint event and as
you've seen causes a recalculation of the scrollbars. There's no harm
in that update() call.

regards,
-Chris

Grant Slender wrote:
> Included here and as an attachment...
>
>
>
> import org.eclipse.nebula.widgets.grid.*;
> import org.eclipse.swt.*;
> import org.eclipse.swt.custom.*;
> import org.eclipse.swt.events.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
>
> public class GridSashSnippet {
>
> public static void main(String[] args) {
> final Display display = new Display ();
> final Shell shell = new Shell (display);
> shell.setLayout(new FormLayout());
>
> SashForm sashForm = new SashForm(shell,SWT.VERTICAL);
> FormData formData = new FormData();
> formData.top = new FormAttachment(0,0);
> formData.left = new FormAttachment(0,0);
> formData.right = new FormAttachment(100,0);
> formData.bottom = new FormAttachment(100,0);
> sashForm.setLayoutData(formData);
> final int nameColumnWidth = 150;
> final int descColumnWidth = 250;
> final int amtColumnWidth = 100;
> final int freqColumnWidth = 120;
>
> final Grid mainGrid= new Grid(sashForm,SWT.BORDER | SWT.V_SCROLL
> | SWT.H_SCROLL);
> mainGrid.setHeaderVisible(true);
> final GridColumn nameColumn = new GridColumn(mainGrid,SWT.NONE);
> nameColumn.setText("Name");
> nameColumn.setTree(true);
> nameColumn.setWidth(nameColumnWidth);
>
> final GridColumn descColumn = new GridColumn(mainGrid,SWT.NONE);
> descColumn.setText("Description / Notes");
>
> final GridColumn amtColumn = new GridColumn(mainGrid,SWT.RIGHT);
> amtColumn.setText("Amount");
> amtColumn.setWidth(amtColumnWidth);
>
> final GridColumn freqColumn = new GridColumn(mainGrid,SWT.CENTER);
> freqColumn.setText("Frequency");
> freqColumn.setWidth(freqColumnWidth);
>
> mainGrid.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> Grid g = (Grid)e.getSource();
> int othercolumns = nameColumn.getWidth() +
> amtColumn.getWidth() + freqColumn.getWidth();
> int size = (g.getSize().x - othercolumns) -
> g.getBorderWidth()*2;
>
> if (g.getVerticalBar().getVisible()) {
> size -= (g.getVerticalBar().getSize().x);
> }
>
> descColumn.setWidth(size < descColumnWidth ?
> descColumnWidth : size);
> /** without a call to update, the grid opens showing an unneeded
> bottom scroll bar
> * that when you move the sash up or down, will go away as it is
> supposed to
> * the problem is that it should open not showing the bottom scroll
> bar !!
> * a call to update here fixes the initial open display problem
> */
> // g.getDisplay().update();
> }
> });
>
> //add some items to the grid
> for (int bc =0; bc < 5;bc++) {
> GridItem item1 = new GridItem(mainGrid,SWT.NONE);
> item1.setText(0,"name"+bc);
> item1.setText(1,"description"+bc);
>
> for (int bi =0; bi < 3;bi++) {
> GridItem item2 = new GridItem(item1,SWT.NONE);
> item2.setText(0,"biname"+bi);
> item2.setText(1,"bidescription"+bi);
> item2.setText(2,bi+"");
> item2.setText(3,"every day");
> }
>
> item1.setExpanded(true);
> }
>
> // add something to the lower part of the shell sashform
> ScrolledComposite sc = new
> ScrolledComposite(sashForm,SWT.H_SCROLL | SWT.V_SCROLL);
> sc.setExpandHorizontal(true);
> sc.setExpandVertical(true);
> sc.setMinSize(450,200);
>
> sashForm.setWeights(new int[] {60,40});
>
> /** in this snippet, calling pack fixes problem and doesn't require
> a call to update.
> * in a larger application (where the grid might be on a tabfolder
> or not just on a simple shell)
> * this does not fix the problem and the call to update is the only
> fix above...
> */
> // shell.pack ();
>
> shell.open ();
> shell.setSize(700,600);
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
> }
>
>
>
> Chris Gross wrote:
>> Hi Grant,
>>
>> The Grid does do some tricky stuff related to recalculating the
>> scrollbars. Can you write a quick snippet that demonstrates the
>> problem you're seeing? Something I can run as a test case?
>>
>> Thanks,
>> -Chris
>>
>
Previous Topic:[grid] Menu popup in void
Next Topic:EclipseCon - BoF - UI Component Programming Best Practices (SWT, Nebula, JFace, Databinding ...)
Goto Forum:
  


Current Time: Tue Jul 22 23:52:58 EDT 2014

Powered by FUDForum. Page generated in 0.03398 seconds