Hi!
I am new to Java and swt. I've just started with eclipse.
I am trying to display a Table in a Tab accessible through a menu item. The code is as follows:
This class handles the Menu action:
|
Code:
|
package swt_trial_my_code;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class TabTable implements IWorkbenchWindowActionDelegate
{
IWorkbenchWindow activeWindow;
MyTabTableExample example;
public void dispose()
{
// TODO Auto-generated method stub
}
public void init(IWorkbenchWindow window)
{
activeWindow = window;
Shell shell = activeWindow.getShell();
Shell tabShell = new Shell(shell);
example = new MyTabTableExample(tabShell);
tabShell.open();
}
public void run(IAction action)
{
// TODO Auto-generated method stub
}
public void selectionChanged(IAction action, ISelection selection)
{
// TODO Auto-generated method stub
}
} |
This class creates a tab folder with only one tab item and should display a table in it:
|
Code:
|
package swt_trial_my_code;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class MyTabTableExample
{
TabFolder tab;
Composite tableComp;
Table table;
TabItem page;
public MyTabTableExample(Shell shell)
{
createTab(shell);
createTable();
createTabItem();
}
private void createTab(Shell shell)
{
tab = new TabFolder(shell,SWT.NONE);
}
private void createTable()
{
tableComp = new Composite(tab,SWT.NONE);
table = new Table(tableComp,SWT.BORDER);
table.setLinesVisible(true);
table.setHeaderVisible(true);
//Columns
TableColumn component = new TableColumn(table, SWT.NONE);
component.setText("Component");
component.setWidth(50);
component.pack();
TableColumn level = new TableColumn(table,SWT.NONE);
level.setText("Level");
level.setWidth(50);
level.pack();
//Items
TableItem row0 = new TableItem(table,SWT.NONE);
row0.setText(new String[] {"abc","Level 1"});
}
private void createTabItem()
{
page = new TabItem(tab,SWT.NONE);
page.setText("Table");
page.setControl(tableComp);
}
} |
However, all I get when I go to 'Hello SWT' is a blank pop up as seen in the image. I can't figure out where i've gone wrong.
Please help me out!