Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Composite in TabItem Not Showing Its Contents
Composite in TabItem Not Showing Its Contents [message #466993] |
Fri, 20 January 2006 17:01 |
Mike Messages: 49 Registered: July 2009 |
Member |
|
|
I can't seem to get a Composite to show its contents after it's been added
to a TabItem. I've looked at the source code in the SWT snippets page on the
eclipse.org website but cannot identify why I see this behaviour.
Can anyone help? The source code is below.
Thanks
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import config.Constants;
public class PreferencesWindow extends ApplicationWindow {
// GUI items
private TabFolder tabs;
private TabItem generalTab;
private TabItem betaTab;
private TabItem advancedTab;
private Button okButton;
private Button cancelButton;
public PreferencesWindow(Shell shell) {
super(shell);
}
@Override
protected Control createContents(Composite parent) {
parent.getShell().setSize(400, 200);
parent.getShell().setText(Constants.PROGRAM_NAME);
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FormLayout());
// tabs
tabs = new TabFolder(composite, SWT.NONE);
generalTab = new TabItem(tabs, SWT.NONE);
generalTab.setText("General");
//as you can see, the control is set to the composite, and is
displayed as you can see the border, but the contents of the composite are
not displayed
generalTab.setControl(initGeneralTab(tabs));
betaTab = new TabItem(tabs, SWT.NONE);
betaTab.setText("Beta");
betaTab.setControl(initBetaTab(tabs));
advancedTab = new TabItem(tabs, SWT.NONE);
advancedTab.setText("Advanced");
// buttons
okButton = new Button(composite, SWT.NONE);
okButton.setText("OK");
cancelButton = new Button(composite, SWT.NONE);
cancelButton.setText("Cancel");
// layout items
FormData fd;
fd = new FormData();
fd.bottom = new FormAttachment(100, -10);
fd.right = new FormAttachment(100, -10);
fd.width = 80;
cancelButton.setLayoutData(fd);
fd = new FormData();
fd.bottom = new FormAttachment(100, -10);
fd.right = new FormAttachment(cancelButton, -5, SWT.LEFT);
fd.width = 80;
okButton.setLayoutData(fd);
fd = new FormData();
fd.top = new FormAttachment(0, 10);
fd.left = new FormAttachment(0, 10);
fd.right = new FormAttachment(100, -10);
fd.bottom = new FormAttachment(okButton, -10, SWT.TOP);
tabs.setLayoutData(fd);
return parent;
}
private Composite initGeneralTab(TabFolder folder) {
Label label;
FormData fd;
List list;
Sash sash;
Button checkBox;
//we show a border here so that we can identify that the composite is
actually displayed
Composite composite = new Composite(folder, SWT.BORDER);
composite.setLayoutData(new FormLayout());
// album art file names label
// for some reason, these widgets are not displayed
label = new Label(composite, SWT.NONE);
label.setText("Album art file names");
fd = new FormData();
fd.left = new FormAttachment(0, 20);
fd.top = new FormAttachment(0, 10);
fd.right = new FormAttachment(100, -10);
fd.bottom = new FormAttachment(100, -10);
label.setLayoutData(fd);
list = new List(composite, SWT.NONE);
fd = new FormData();
fd.top = new FormAttachment(label, 5, SWT.BOTTOM);
fd.left = new FormAttachment(label, 10, SWT.LEFT);
list.setLayoutData(fd);
sash = new Sash(composite, SWT.HORIZONTAL);
fd = new FormData();
fd.top = new FormAttachment(list, 5, SWT.BOTTOM);
fd.left = new FormAttachment(label, 0, SWT.LEFT);
fd.right = new FormAttachment(100, -10);
sash.setLayoutData(fd);
checkBox = new Button(composite, SWT.CHECK);
fd = new FormData();
fd.top = new FormAttachment(sash, 5, SWT.BOTTOM);
fd.right = new FormAttachment(label, -5, SWT.LEFT);
checkBox.setLayoutData(fd);
label = new Label(composite, SWT.NONE);
label.setText("Scan for new music in");
fd = new FormData();
fd.left = new FormAttachment(label, 0, SWT.LEFT);
fd.right = new FormAttachment(100, -10);
fd.top = new FormAttachment(checkBox, 0, SWT.TOP);
label.setLayoutData(fd);
return composite;
}
private Composite initBetaTab(TabFolder folder) {
Label label;
FormData fd;
Button checkBox;
Composite composite = new Composite(folder, SWT.BORDER);
composite.setLayoutData(new FormLayout());
// album art file names label
label = new Label(composite, SWT.NONE);
label.setText("Allow sending of colour profiles");
fd = new FormData();
fd.left = new FormAttachment(0, 20);
fd.top = new FormAttachment(0, 10);
fd.right = new FormAttachment(100, -10);
label.setLayoutData(fd);
checkBox = new Button(composite, SWT.CHECK);
fd = new FormData();
fd.top = new FormAttachment(label, 5, SWT.TOP);
fd.right = new FormAttachment(label, -5, SWT.LEFT);
checkBox.setLayoutData(fd);
return composite;
}
public static void main(String[] args) {
PreferencesWindow window = new PreferencesWindow(new Shell(
new Display()));
window.setBlockOnOpen(true);
window.open();
}
}
|
|
| |
Goto Forum:
Current Time: Sun Dec 08 06:35:24 GMT 2024
Powered by FUDForum. Page generated in 0.03226 seconds
|