我正在使用 Zest 中的树布局显示模型。但是,我指定在每个节点中显示的文本太长了。我希望文本移动到节点内的下一行,以便可以显示所有文本,而不是截断大部分文本。我尝试对添加到图中的每个节点使用 setSize() ,但这似乎没有任何区别。谁能告诉我如何实现这一目标?谢谢。* 我添加了显示当前单词被截断的情况的代码。
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.CGraphNode;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.ImageFigure;
//import org.eclipse.zest.layout.algorithms.RadialLayoutAlgorithm;
//import org.eclipse.zest.layout.interfaces.LayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
public class TreeLayoutExample {
public static void main(String[] args) {
// Create the shell
Display d = new Display();
Shell shell = new Shell(d);
shell.setText("GraphSnippet1");
shell.setLayout(new FillLayout());
shell.setSize(500, 500);
final Graph g = new Graph(shell, SWT.NONE);
g.setSize(500, 500);
GraphNode root = new GraphNode(g, SWT.NONE, "");
root.setSize(1000, 1000);
for (int i = 0; i < 3; i++) {
GraphNode n = new GraphNode(g, SWT.NONE, "GIANT LONG TEXT");
n.setSize(300, 300);
for (int j = 0; j < 3; j++) {
GraphNode n2 = new GraphNode(g, SWT.NONE, "MORE GIANT LONG TEXT");
n2.setSize(300, 300);
new GraphConnection(g, SWT.NONE, n, n2).setWeight(-1);
}
new GraphConnection(g, SWT.NONE, root, n);
}
final TreeLayoutAlgorithm layoutAlgorithm = new org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm();
g.setLayoutAlgorithm(layoutAlgorithm, true);
shell.open();
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}
}
}