Topic: 关于SWT的SashForm

  Print this page

1.关于SWT的SashForm Copy to clipboard
Posted by: tssungeng
Posted on: 2005-04-18 23:43

我通过下面的代码得到如图(图在下面)的一个窗口,但是我想让窗口打开后左侧的TreeViewer是200像素,右侧上面部分的TableViewer是200像素高,请问怎么做?

代码如下(非完整版):

import java.io.*;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.widgets.*;
public class Explorer extends ApplicationWindow
{
public Explorer()
{
super(null);
this.addMenuBar();
}
//protected void addMenuBar(){}

protected Control createContents(Composite parent)
{
SashForm sash_form = new SashForm(parent, SWT.HORIZONTAL | SWT.NULL);
//sash_form.setSize(100,200);
TreeViewer tv = new TreeViewer(sash_form);

tv.setContentProvider(new FileTreeContentProvider());
tv.setLabelProvider(new FileTreeLabelProvider());
tv.setInput(new File("D:\\"));
SashForm sf = new SashForm(sash_form ,SWT.VERTICAL | SWT.NULL);
//sash_form.setSize(300,200);
final TableViewer tbv = new TableViewer(sf, SWT.BORDER);
tbv.setContentProvider(new FileTableContentProvider());
tv.addSelectionChangedListener(new ISelectionChangedListener()
{
public void selectionChanged(SelectionChangedEvent event)
{
IStructuredSelection selection =
(IStructuredSelection) event.getSelection();
Object selected_file = selection.getFirstElement();
tbv.setInput(selected_file);
}
});

Button b = new Button(sf, SWT.PUSH);
b.setText("Hello World");




return sash_form;
}


protected MenuManager createMenuManager()
{
MenuManager bar_menu = new MenuManager("");

MenuManager file_menu = new MenuManager("&File");
MenuManager edit_menu = new MenuManager("&Edit");
MenuManager view_menu = new MenuManager("&View");

bar_menu.add(file_menu);
bar_menu.add(edit_menu);
bar_menu.add(view_menu);

file_menu.add(new ExitAction(this));
//file_menu.add(new ExitAction(this));
//edit_menu.add("&Usdafndo");

return bar_menu;
}


public static void main(String[] args)
{
Explorer w = new Explorer();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
//Shell shell = new Shell(Display);
}
}

2.Re:关于SWT的SashForm [Re: tssungeng] Copy to clipboard
Posted by: kite
Posted on: 2005-04-19 10:49

用GridLayout(不用SashForm)或者定义SashForm的weights-根据你当前的窗口的size计算比例,然后sashForm.setWeights();

3.Re:关于SWT的SashForm [Re: tssungeng] Copy to clipboard
Posted by: tssungeng
Posted on: 2005-04-19 21:14

感谢kite!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923