Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » One Table Hides Another when Window Re-Sizes
One Table Hides Another when Window Re-Sizes [message #467607] Wed, 01 February 2006 19:41 Go to next message
Eddie Atherton is currently offline Eddie AthertonFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,

I've set up 2 Tables in a Group. I want both to expand out to fill
the available window using the following:

// Dir and File
currDir = new Group(main_shell, SWT.NONE);
currDir.setText("home");
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
currDir.setLayout(gridLayout);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 3;
currDir.setLayoutData(gridData);
tDirs = new Table(currDir, SWT.BORDER | SWT.V_SCROLL |
SWT.H_SCROLL);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 3;
tDirs.setLayoutData(gridData);
tDirs.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
network_stuff.sendChangeDir(xml,
tDirs.getItem(tDirs.getSelectionIndex()).getText());
ResyncDir();
}
});

tFiles = new Table(currDir, SWT.BORDER | SWT.V_SCROLL
| SWT.H_SCROLL);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 3;
tFiles.setLayoutData(gridData);

Menu mPop = new Menu(main_shell, SWT.POP_UP);
MenuItem reloadItem = new MenuItem(mPop, SWT.CASCADE);
reloadItem.setText("Reload");
reloadItem.addListener (SWT.Selection, new Listener ()
{
public void handleEvent (Event event) {
System.out.println(event.toString());
System.out.println ("Reload
Selected");
}
});
MenuItem replayItem = new MenuItem(mPop, SWT.CASCADE);
replayItem.setText("Replay");
replayItem.addListener (SWT.Selection, new Listener ()
{
public void handleEvent (Event event) {
System.out.println(event.toString());
System.out.println ("Replay
Selected");
}
});
tFiles.setMenu(mPop);
// Needed to capture which File selected for PopUp Menu
above
tFiles.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
System.out.println(event.toString());
System.out.println ("File " +
event.item + " Selected");
}
});

This appears to work. But, if there are only a handful of entries in
the tDirs table and hundreds in the tFiles, then any attempt to resize
the window causes the tFiles window to fill the area, and I can't get
the tDirs one back without re-starting.

How can I force it so the 2 tables are always shown, with no regard to
how many entries there are.

I DON'T want to use explicit sizing for these, as the application will
run on both a PocketPC and also a Desktop. Unless there's a way to
handle that programatically.

Cheers,
Eddie
Re: One Table Hides Another when Window Re-Sizes [message #467778 is a reply to message #467607] Mon, 06 February 2006 16:56 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
The way GridLayout works is that when a bunch of widgets are trying to fill
the vertical space, the available space is shared between the widgets based
on the result of Widget.computeSize(SWT.DEFAULT, SWT.DEFAULT). The table
with many more items will return a result that is much bigger and as a
result, it will consume a higher percent of the available space. The way
around this is to specify a GridData.heightHint. The heightHint will be
used instead of the result from Widget.computeSize(). The heightHint will
not prevent the widget from filling the available space. However it will
affect the result if you choose to pack the parent (or any parent up to and
including the shell). But you probably don't want to pack the parent anyway
because without the heightHint, a table with many entries will result in a
very large parent.


public static void main (String [] args) {
Display display = new Display ();
Shell main_shell = new Shell (display);
main_shell.setLayout(new GridLayout());

// Dir and File
Group currDir = new Group(main_shell, SWT.NONE);
currDir.setText("home");
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
currDir.setLayout(gridLayout);
GridData gridData = new GridData(GridData.FILL_BOTH);
//gridData.horizontalSpan = 3;
currDir.setLayoutData(gridData);

Table tDirs = new Table(currDir, SWT.BORDER | SWT.V_SCROLL |
SWT.H_SCROLL);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 3;
gridData.heightHint = 10;
tDirs.setLayoutData(gridData);
for (int i = 0; i < 200; i++) {
TableItem item = new TableItem(tDirs, SWT.NONE);
item.setText("item "+i);
}

Table tFiles = new Table(currDir, SWT.BORDER | SWT.V_SCROLL |
SWT.H_SCROLL);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 3;
gridData.heightHint = 10;
tFiles.setLayoutData(gridData);
for (int i = 0; i < 15; i++) {
TableItem item = new TableItem(tFiles, SWT.NONE);
item.setText("item "+i);
}


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


"Eddie Atherton" <Trouble@Mill.> wrote in message
news:5032u11m0mrnca1ebov335ttkqfnlvkd79@4ax.com...
> Hi,
>
> I've set up 2 Tables in a Group. I want both to expand out to fill
> the available window using the following:
>
> // Dir and File
> currDir = new Group(main_shell, SWT.NONE);
> currDir.setText("home");
> gridLayout = new GridLayout();
> gridLayout.numColumns = 3;
> currDir.setLayout(gridLayout);
> gridData = new GridData(GridData.FILL_BOTH);
> gridData.horizontalSpan = 3;
> currDir.setLayoutData(gridData);
> tDirs = new Table(currDir, SWT.BORDER | SWT.V_SCROLL |
> SWT.H_SCROLL);
> gridData = new GridData(GridData.FILL_BOTH);
> gridData.horizontalSpan = 3;
> tDirs.setLayoutData(gridData);
> tDirs.addListener (SWT.Selection, new Listener () {
> public void handleEvent (Event event) {
> network_stuff.sendChangeDir(xml,
> tDirs.getItem(tDirs.getSelectionIndex()).getText());
> ResyncDir();
> }
> });
>
> tFiles = new Table(currDir, SWT.BORDER | SWT.V_SCROLL
> | SWT.H_SCROLL);
> gridData = new GridData(GridData.FILL_BOTH);
> gridData.horizontalSpan = 3;
> tFiles.setLayoutData(gridData);
>
> Menu mPop = new Menu(main_shell, SWT.POP_UP);
> MenuItem reloadItem = new MenuItem(mPop, SWT.CASCADE);
> reloadItem.setText("Reload");
> reloadItem.addListener (SWT.Selection, new Listener ()
> {
> public void handleEvent (Event event) {
> System.out.println(event.toString());
> System.out.println ("Reload
> Selected");
> }
> });
> MenuItem replayItem = new MenuItem(mPop, SWT.CASCADE);
> replayItem.setText("Replay");
> replayItem.addListener (SWT.Selection, new Listener ()
> {
> public void handleEvent (Event event) {
> System.out.println(event.toString());
> System.out.println ("Replay
> Selected");
> }
> });
> tFiles.setMenu(mPop);
> // Needed to capture which File selected for PopUp Menu
> above
> tFiles.addListener (SWT.Selection, new Listener () {
> public void handleEvent (Event event) {
> System.out.println(event.toString());
> System.out.println ("File " +
> event.item + " Selected");
> }
> });
>
> This appears to work. But, if there are only a handful of entries in
> the tDirs table and hundreds in the tFiles, then any attempt to resize
> the window causes the tFiles window to fill the area, and I can't get
> the tDirs one back without re-starting.
>
> How can I force it so the 2 tables are always shown, with no regard to
> how many entries there are.
>
> I DON'T want to use explicit sizing for these, as the application will
> run on both a PocketPC and also a Desktop. Unless there's a way to
> handle that programatically.
>
> Cheers,
> Eddie
Re: One Table Hides Another when Window Re-Sizes [message #467795 is a reply to message #467778] Mon, 06 February 2006 19:49 Go to previous message
Eddie Atherton is currently offline Eddie AthertonFriend
Messages: 8
Registered: July 2009
Junior Member
On Mon, 6 Feb 2006 11:56:29 -0500, "Veronika Irvine"
<veronika_irvine@oti.com> wrote:

>The way GridLayout works is that when a bunch of widgets are trying to fill
>the vertical space, the available space is shared between the widgets based
>on the result of Widget.computeSize(SWT.DEFAULT, SWT.DEFAULT). The table
>with many more items will return a result that is much bigger and as a
>result, it will consume a higher percent of the available space. The way
>around this is to specify a GridData.heightHint. The heightHint will be
>used instead of the result from Widget.computeSize(). The heightHint will
>not prevent the widget from filling the available space. However it will
>affect the result if you choose to pack the parent (or any parent up to and
>including the shell). But you probably don't want to pack the parent anyway
>because without the heightHint, a table with many entries will result in a
>very large parent.

Absolutely perfect. Thank you very much.

Cheers,
Eddie
Previous Topic:Embedding objects in styledtext - Snippet 212 questions
Next Topic:SWT Undo Manual/Tutorial/Examples?
Goto Forum:
  


Current Time: Thu Aug 22 00:11:28 GMT 2019

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

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

Back to the top