Мне нужна помощь, как разместить панель инструментов и таблицу в одном окне SWT оболочки.
Проблема в том, что если у меня есть обе формы по форме, каждая из них покрывает одну половину окна оболочки:
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.ToolItem;
public class MainLayout {
protected Shell shell;
private Table table;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
MainLayout window = new MainLayout();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new FillLayout(SWT.HORIZONTAL));
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);
MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
menuItem.setText("New SubMenu");
Menu menu_2 = new Menu(menuItem);
menuItem.setMenu(menu_2);
table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
//ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
ToolBar toolBar = new ToolBar(shell, SWT.HORIZONTAL);
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
item.setText("Button One");
}
}
Можете ли вы мне помочь, пожалуйста?
Вместо этого используйте GridLayout. Вам также необходимо настроить GridData для настройки макета виджетов.
Пример кода:
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new GridLayout(1,false)); // change
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);
MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
menuItem.setText("New SubMenu");
Menu menu_2 = new Menu(menuItem);
menuItem.setMenu(menu_2);
table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION );
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // change
//ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
ToolBar toolBar = new ToolBar(shell, SWT.HORIZONTAL);
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
item.setText("Button One");
}
Рекомендации: