Tolgar
asked on
How to create a window with 3 tabs in JAVA SWT?
Hi,
I just started to work with JAVA SWT package.
Can you please send me a sample code which creates a window that has 3 tabs in it by using swt package?
And the tab names will be A, B and C.
Thanks,
I just started to work with JAVA SWT package.
Can you please send me a sample code which creates a window that has 3 tabs in it by using swt package?
And the tab names will be A, B and C.
Thanks,
ASKER
How can I move these tab to the top left corner of the page?
and is there a way to set the size of the initial window to a certain value?
and is there a way to set the size of the initial window to a certain value?
ASKER
without digging into the API it looks like you could replace SWT.BOTTOM with SWT.TOP
API reference can be found here:
http://www.eclipse.org/swt/docs.php
if you can't locate it I can do search through it.
API reference can be found here:
http://www.eclipse.org/swt/docs.php
if you can't locate it I can do search through it.
ASKER
Ok. I made the tabs on the top. Now, how can I create the icons in the first tab as shown in the mock up that I sent?
this should help you understand how that works.
http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html
Do you have a good IDE that you are able to test in?
it helps to tinker and see what the different options can do and how they work.
http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html
Do you have a good IDE that you are able to test in?
it helps to tinker and see what the different options can do and how they work.
ASKER
Ok. Now I managed to add the button but I cannot generate the tabs anymore.
What am I missing?
What am I missing?
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
public class Gui {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
// Create the layout.
RowLayout layout = new RowLayout();
// Optionally set layout fields.
layout.wrap = true;
// Set the layout into the composite.
shell.setLayout(layout);
// Create the children of the composite.
new Button(shell, SWT.PUSH).setText("B1");
new Button(shell, SWT.PUSH).setText("Wide Button 2");
new Button(shell, SWT.PUSH).setText("Button 3");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
FillLayout fillLayout = new FillLayout();
fillLayout.type = SWT.VERTICAL;
shell.setLayout(fillLayout);
new Button(shell, SWT.PUSH).setText("B1");
new Button(shell, SWT.PUSH).setText("Wide Button 2");
new Button(shell, SWT.PUSH).setText("Button 3");
fillLayout.type = SWT.HORIZONTAL;
RowLayout rowLayout = new RowLayout();
rowLayout.wrap = false;
rowLayout.pack = false;
rowLayout.justify = true;
rowLayout.type = SWT.VERTICAL;
rowLayout.marginLeft = 5;
rowLayout.marginTop = 5;
rowLayout.marginRight = 5;
rowLayout.marginBottom = 5;
rowLayout.spacing = 0;
shell.setLayout(rowLayout);
rowLayout.wrap = true;
rowLayout.pack = true;
rowLayout.justify = false;
rowLayout.type = SWT.HORIZONTAL;
shell.setLayout(new GridLayout());
// SWT.BOTTOM to show at the bottom
CTabFolder folder = new CTabFolder(shell, SWT.TOP);
GridData data = new GridData(GridData.FILL,
GridData.FILL, true, true,
20, 10);
folder.setLayoutData(data);
CTabItem cTabItem1 = new CTabItem(folder, SWT.NONE);
cTabItem1.setText("Tab1");
CTabItem cTabItem2 = new CTabItem(folder, SWT.NONE);
cTabItem2.setText("Tab2");
CTabItem cTabItem3 = new CTabItem(folder, SWT.NONE);
cTabItem3.setText("Tab3");
Text text = new Text(folder, SWT.BORDER);
text.setText("You can type the list of files in this field");
cTabItem1.setControl(text);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
I'll have to leave that for another expert. I don't have an swt environment setup.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Open in new window