我一直在学习本教程,将JTree组件嵌入到Eclipse视图中。
http://www.java2s.com/Tutorial/Java/0280__SWT/EmbededSwingAWTcomponentstoSWT.htm
我遇到的问题是它没有打印整个树,我无法弄清楚如何使用SWT或Swing的不同布局来调整它的大小。
顺便说一句,我对嵌入Swt的Swing组件完全不熟悉。
这是我的代码,以及显示显示问题的屏幕截图:
import javax.swing.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.part.ViewPart;
import testbutton.handlers.SampleHandler;
public class viewMap4j extends ViewPart {
public viewMap4j() {
// TODO Auto-generated constructor stub
}
@Override
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
parent.setLayout(new RowLayout());
Button newProject = new Button(parent, SWT.COLOR_DARK_BLUE);
newProject.setText("New project");
newProject.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.Selection:
// Some Methods..
break;
}
}
});
Button generate = new Button(parent, SWT.COLOR_DARK_BLUE);
generate.setText("Generate...");
generate.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.Selection:
// Some Methods..
break;
}
}
});
Button openProject = new Button(parent, SWT.COLOR_DARK_BLUE);
openProject.setText("Open project");
openProject.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.Selection:
// Some Methods..
break;
}
}
});
Button saveProject = new Button(parent, SWT.COLOR_DARK_BLUE);
saveProject.setText("Save");
saveProject.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.Selection:
// Some Methods..
break;
}
}
});
Composite jtreeComp = new Composite(parent, SWT.EMBEDDED);
// jtreeComp.setBounds(500,500,800,800);
jtreeComp.setSize(1000, 1000);
java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(jtreeComp);
java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout());
fileTableFrame.add(panel);
JTree fileTable = new JTree();
fileTable.setSize(300, 300);
fileTable.setDoubleBuffered(true);
JScrollPane scrollPane = new JScrollPane(fileTable);
panel.add(scrollPane);
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
}
有什么想法吗?