Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » layout problem
layout problem [message #442713] Mon, 13 September 2004 07:40 Go to next message
Michael Seele is currently offline Michael SeeleFriend
Messages: 124
Registered: July 2009
Senior Member
hi,
i want layout my ui following:
on the left upper edge there is a text, on the right uper edge there are
two buttons and in the second row all the horizontal and vertical space
will be given to a table!
this is my code:

public void createPartControl(Composite parent) {
parent.setBackground(new Color(parent.getDisplay(), 255, 255, 255));
parent.setLayout(new GridLayout(4, false));

Label textLabel = new Label(parent, SWT.NONE);
textLabel.setBackground(parent.getBackground());
textLabel.setForeground(new Color(textLabel.getDisplay(), 195, 209,
224));
textLabel.setFont(new Font(textLabel.getDisplay(), "", 14, SWT.BOLD));
textLabel.setText(this.getLeadingFilename() + " ResourceBundle");

Canvas spacer = new Canvas(parent, SWT.NONE);
//spacer.setBackground(parent.getBackground());

Button addLineButton = new Button(parent, SWT.NONE);
addLineButton.setBackground(parent.getBackground());
addLineButton.setImage(Util.createImage("icons/addRow.gif"));

Button removeLineButton = new Button(parent, SWT.NONE);
removeLineButton.setBackground(parent.getBackground());
removeLineButton.setImage(Util.createImage("icons/deleteRow.gif "));

TableViewer tableViewer = new TableViewer(parent, SWT.SINGLE |
SWT.BORDER);
Table table = tableViewer.getTable();
TableColumn tableColumn = new TableColumn(table, SWT.LEFT | SWT.FILL);
tableColumn.setText("Key");
tableColumn = new TableColumn(table, SWT.LEFT | SWT.FILL);
tableColumn.setText("deutsch - Deutschland");
TableItem tableItem = new TableItem(table, SWT.LEFT, 0);
tableItem.setText(0, "w");
tableItem.setText(1, "a");
tableItem = new TableItem(table, SWT.LEFT, 1);
tableItem.setText(0, "x");
tableItem.setText(1, "b");
tableItem = new TableItem(table, SWT.LEFT, 2);
tableItem.setText(0, "y");
tableItem.setText(1, "c");
tableItem = new TableItem(table, SWT.LEFT, 3);
tableItem.setText(0, "z");
tableItem.setText(1, "d");
table.setHeaderVisible(true);
table.setLinesVisible(true);

GridData gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
textLabel.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
spacer.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
addLineButton.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
removeLineButton.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
removeLineButton.setLayoutData(gridData);
}

wheres the bug? what are my mistakes?
thank you!!!
Re: layout problem [message #442940 is a reply to message #442713] Wed, 15 September 2004 15:28 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
1)
GridData gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
textLabel.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
spacer.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
addLineButton.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
removeLineButton.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
//removeLineButton.setLayoutData(gridData); //!!!! Oops - assigned data to
wrong widget
table.setLayoutData(gridData);

2)

In 3.1, the above code will work as you expect. In 3.0 however, GridLayout
has a funny habit of making the last column expandable when you span
multiple columns. So in 3.0 and 3.1 the following works:

GridData gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
textLabel.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
spacer.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
addLineButton.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
removeLineButton.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.FILL, false, true, 4, 1); // Don't
grab horizontal here, the spacer is already achieving this for you
table.setLayoutData(gridData);



"Michael Seele" <mseele@guh-software.de> wrote in message
news:ci3ism$qn4$1@eclipse.org...
> hi,
> i want layout my ui following:
> on the left upper edge there is a text, on the right uper edge there are
> two buttons and in the second row all the horizontal and vertical space
> will be given to a table!
> this is my code:
>
> public void createPartControl(Composite parent) {
> parent.setBackground(new Color(parent.getDisplay(), 255, 255, 255));
> parent.setLayout(new GridLayout(4, false));
>
> Label textLabel = new Label(parent, SWT.NONE);
> textLabel.setBackground(parent.getBackground());
> textLabel.setForeground(new Color(textLabel.getDisplay(), 195, 209,
> 224));
> textLabel.setFont(new Font(textLabel.getDisplay(), "", 14, SWT.BOLD));
> textLabel.setText(this.getLeadingFilename() + " ResourceBundle");
>
> Canvas spacer = new Canvas(parent, SWT.NONE);
> //spacer.setBackground(parent.getBackground());
>
> Button addLineButton = new Button(parent, SWT.NONE);
> addLineButton.setBackground(parent.getBackground());
> addLineButton.setImage(Util.createImage("icons/addRow.gif"));
>
> Button removeLineButton = new Button(parent, SWT.NONE);
> removeLineButton.setBackground(parent.getBackground());
> removeLineButton.setImage(Util.createImage("icons/deleteRow.gif "));
>
> TableViewer tableViewer = new TableViewer(parent, SWT.SINGLE |
> SWT.BORDER);
> Table table = tableViewer.getTable();
> TableColumn tableColumn = new TableColumn(table, SWT.LEFT | SWT.FILL);
> tableColumn.setText("Key");
> tableColumn = new TableColumn(table, SWT.LEFT | SWT.FILL);
> tableColumn.setText("deutsch - Deutschland");
> TableItem tableItem = new TableItem(table, SWT.LEFT, 0);
> tableItem.setText(0, "w");
> tableItem.setText(1, "a");
> tableItem = new TableItem(table, SWT.LEFT, 1);
> tableItem.setText(0, "x");
> tableItem.setText(1, "b");
> tableItem = new TableItem(table, SWT.LEFT, 2);
> tableItem.setText(0, "y");
> tableItem.setText(1, "c");
> tableItem = new TableItem(table, SWT.LEFT, 3);
> tableItem.setText(0, "z");
> tableItem.setText(1, "d");
> table.setHeaderVisible(true);
> table.setLinesVisible(true);
>
> GridData gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
> textLabel.setLayoutData(gridData);
> gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
> spacer.setLayoutData(gridData);
> gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
> addLineButton.setLayoutData(gridData);
> gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
> removeLineButton.setLayoutData(gridData);
> gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
> removeLineButton.setLayoutData(gridData);
> }
>
> wheres the bug? what are my mistakes?
> thank you!!!
>
Previous Topic:how to create sub menu item in jface?
Next Topic:Extended Tree Control?
Goto Forum:
  


Current Time: Fri Apr 26 17:06:59 GMT 2024

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

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

Back to the top