Java 启用文本溢出到下一行Zest Draw2d SWT
我使用Zest中的树布局显示模型。但是,我指定在每个节点中显示的文本太长。我希望文本移动到节点内的下一行,以便可以显示所有文本,而不是将大部分文本截断。我尝试对添加到图中的每个节点使用setSize(),但这似乎没有任何区别。谁能告诉我如何才能做到这一点?谢谢我添加了代码,显示了当前的情况,即单词被截断Java 启用文本溢出到下一行Zest Draw2d SWT,java,user-interface,swt,draw2d,zest,Java,User Interface,Swt,Draw2d,Zest,我使用Zest中的树布局显示模型。但是,我指定在每个节点中显示的文本太长。我希望文本移动到节点内的下一行,以便可以显示所有文本,而不是将大部分文本截断。我尝试对添加到图中的每个节点使用setSize(),但这似乎没有任何区别。谁能告诉我如何才能做到这一点?谢谢我添加了代码,显示了当前的情况,即单词被截断 import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout
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();
}
}
}
}
import org.eclipse.swt.swt;
导入org.eclipse.swt.graphics.Image;
导入org.eclipse.swt.layout.FillLayout;
导入org.eclipse.swt.widgets.Display;
导入org.eclipse.swt.widgets.Shell;
导入org.eclipse.zest.core.widgets.CGraphNode;
导入org.eclipse.zest.core.widgets.Graph;
导入org.eclipse.zest.core.widgets.GraphConnection;
导入org.eclipse.zest.core.widgets.GraphNode;
导入org.eclipse.draw2d.FigureCanvas;
导入org.eclipse.draw2d.ImageFigure;
//导入org.eclipse.zest.layout.algorithms.radialYoutAlgorithm;
//导入org.eclipse.zest.layout.interfaces.LayoutAlgorithm;
导入org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
公共类TreeLayoutExample{
公共静态void main(字符串[]args){
//创建shell
显示d=新显示();
外壳=新外壳(d);
shell.setText(“GraphStippet1”);
setLayout(新的FillLayout());
外壳尺寸(500500);
最终图形g=新图形(外壳,SWT.NONE);
g、 设置大小(500500);
GraphNode根=新GraphNode(g,SWT.NONE,“”);
root.setSize(10001000);
对于(int i=0;i<3;i++){
GraphNode n=新的GraphNode(g,SWT.NONE,“巨型长文本”);
n、 设置大小(300300);
对于(int j=0;j<3;j++){
GraphNode n2=新的GraphNode(g,SWT.NONE,“更大的长文本”);
n2.设置尺寸(300300);
新图形连接(g,SWT.NONE,n,n2)。设定重量(-1);
}
新图形连接(g、SWT.NONE、root、n);
}
final TreeLayoutAlgorithm layoutAlgorithm=new org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm();
g、 setLayoutAlgorithm(layoutAlgorithm,true);
shell.open();
而(!shell.isDisposed()){
而(!d.readAndDispatch()){
d、 睡眠();
}
}
}
}
这个问题的解决方案并不十分直观,但下面是:
LayoutStyles.NO\u LAYOUT\u NODE\u RESIZING
作为样式传递到treeAyoutAlgorithm
:
TreeLayoutAlgorithm layoutAlgorithm = new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING);
setSize(-1,-1)
public static void main(String[] args)
{
Display d = new Display();
Shell shell = new Shell(d);
shell.setText("GraphSnippet1");
shell.setLayout(new FillLayout());
shell.setSize(1280, 500);
final Graph g = new Graph(shell, SWT.NONE);
g.setSize(-1, -1);
GraphNode root = new GraphNode(g, SWT.NONE, "ROOT");
root.setSize(-1, -1);
for (int i = 0; i < 3; i++)
{
GraphNode n = new GraphNode(g, SWT.NONE, "LONG TEXT");
n.setSize(-1, -1);
for (int j = 0; j < 2; j++)
{
GraphNode n2 = new GraphNode(g, SWT.NONE, "EVEN LONGER TEXT");
n2.setSize(-1, -1);
new GraphConnection(g, SWT.NONE, n, n2).setWeight(-1);
}
new GraphConnection(g, SWT.NONE, root, n);
}
TreeLayoutAlgorithm layoutAlgorithm = new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING);
g.setLayoutAlgorithm(layoutAlgorithm, true);
shell.open();
while (!shell.isDisposed())
{
while (!d.readAndDispatch())
{
d.sleep();
}
}
}
publicstaticvoidmain(字符串[]args)
{
显示d=新显示();
外壳=新外壳(d);
shell.setText(“GraphStippet1”);
setLayout(新的FillLayout());
外壳尺寸(1280500);
最终图形g=新图形(外壳,SWT.NONE);
g、 设置大小(-1,-1);
GraphNode root=新的GraphNode(g,SWT.NONE,“root”);
root.setSize(-1,-1);
对于(int i=0;i<3;i++)
{
GraphNode n=新的GraphNode(g,SWT.NONE,“长文本”);
n、 设置大小(-1,-1);
对于(int j=0;j<2;j++)
{
GraphNode n2=新的GraphNode(g,SWT.NONE,“甚至更长的文本”);
n2.设置大小(-1,-1);
新图形连接(g,SWT.NONE,n,n2)。设定重量(-1);
}
新图形连接(g、SWT.NONE、root、n);
}
TreeLayoutAlgorithm layoutAlgorithm=新的TreeLayoutAlgorithm(LayoutStyles.无布局\节点\调整大小);
g、 setLayoutAlgorithm(layoutAlgorithm,true);
shell.open();
而(!shell.isDisposed())
{
而(!d.readAndDispatch())
{
d、 睡眠();
}
}
}
看起来像这样:
你能发布一个代码示例吗?@Baz尽管调整了节点的大小,我还是添加了代码来演示我的当前情况。非常感谢。然而,当所有节点元素的长度不尽相同时,树就会变得非常混乱。你知道有什么特别的解决方案允许节点内的文本只转到下一行,而不是仅仅扩展宽度以适应吗?@Asher可能会有所帮助。