Java youtStyles.NO_布局_节点_大小调整),true); graph.setHorizontalScrollBarVisibility(graph.ALWAYS); graph.setVerticalScrollBarVisibility(graph.ALWAYS); //用一些节点填充图形并连接它们 GraphNode1=新GraphNode(图,SWT.NONE,“Earendil”); GraphNode2=新GraphNode(图,SWT.NONE,“Elros”); GraphNode3=新GraphNode(图,SWT.NONE,“Elrond”); GraphNode4=新GraphNode(图,SWT.NONE,“Elladan”); GraphNode节点5=新GraphNode(图,SWT.NONE,“Elrohir”); GraphNode6=新GraphNode(图,SWT.NONE,“Arwen”); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点1、节点2); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点1、节点3); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点2、节点4); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点2、节点5); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点2、节点6); /* 此graphViewer由两个组件组成:控件和图形(图) 我们希望根据布局为控件指定一个大小,并为图形指定一个自定义的、更大的值。 对于控件(graphViewer.getControl),我只需获取所有可用空间 */ GridDataFactory.fillDefaults().grab(true,true.applyTo(graphViewer.getControl()); //对于图形,我们必须创建一个PaintListener。 graph.addPaintListener(新的PaintListener(){ @凌驾 公共无效油漆控制(油漆事件e){ 图形设置大小(13001080); } }); //该图现在填充外壳/父复合结构, //但实际的图形大小可以在paint//listener中根据需要设置 //使用org.eclipse.gef.editparts.ZoomManager类进行缩放 //作为参数,我们需要一个可缩放的图形,它由graph.getRootLayer和视口接收。 ZoomManager ZoomManager=新的ZoomManager(graph.getRootLayer(),graph.getViewport()); //我们将缩放机制绑定到一个简单的鼠标滚轮侦听器 graph.addMouseWheelListener(新的MouseWheelListener(){ @凌驾 公共空鼠标滚动(MouseEvent e){ 如果(e.计数
注意:我没有包括导入内容如果您认为答案解决了问题,请单击绿色复选标记将其标记为“已接受”。这有助于将注意力集中在仍然没有答案的旧帖子上。如果您认为答案解决了问题,请单击绿色复选标记将其标记为“已接受”。这有助于保持对仍然没有答案的旧帖子的关注。感谢awnser,我实际上设法让它与复合和SashForm混合使用,并在完成后发布代码。感谢awnser,事实上,我成功地将它与复合和SashForm混合使用,并将在完成后发布代码。这实际上不起作用。是的,图形可以滚动,但是它从GridLayout中获得分配的空间,而GridLayout不会扩展。因此,图形只是停留在其边界内,可以滚动,但不会主动获得更多空间。这实际上不起作用。是的,图形可以滚动,但是它从GridLayout中获得分配的空间,而GridLayout不会扩展。因此,图形只是停留在其边界内,可以滚动,但不会主动获得更多空间Java youtStyles.NO_布局_节点_大小调整),true); graph.setHorizontalScrollBarVisibility(graph.ALWAYS); graph.setVerticalScrollBarVisibility(graph.ALWAYS); //用一些节点填充图形并连接它们 GraphNode1=新GraphNode(图,SWT.NONE,“Earendil”); GraphNode2=新GraphNode(图,SWT.NONE,“Elros”); GraphNode3=新GraphNode(图,SWT.NONE,“Elrond”); GraphNode4=新GraphNode(图,SWT.NONE,“Elladan”); GraphNode节点5=新GraphNode(图,SWT.NONE,“Elrohir”); GraphNode6=新GraphNode(图,SWT.NONE,“Arwen”); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点1、节点2); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点1、节点3); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点2、节点4); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点2、节点5); 新图形连接(图形、ZestStyles.CONNECTIONS\u定向、节点2、节点6); /* 此graphViewer由两个组件组成:控件和图形(图) 我们希望根据布局为控件指定一个大小,并为图形指定一个自定义的、更大的值。 对于控件(graphViewer.getControl),我只需获取所有可用空间 */ GridDataFactory.fillDefaults().grab(true,true.applyTo(graphViewer.getControl()); //对于图形,我们必须创建一个PaintListener。 graph.addPaintListener(新的PaintListener(){ @凌驾 公共无效油漆控制(油漆事件e){ 图形设置大小(13001080); } }); //该图现在填充外壳/父复合结构, //但实际的图形大小可以在paint//listener中根据需要设置 //使用org.eclipse.gef.editparts.ZoomManager类进行缩放 //作为参数,我们需要一个可缩放的图形,它由graph.getRootLayer和视口接收。 ZoomManager ZoomManager=新的ZoomManager(graph.getRootLayer(),graph.getViewport()); //我们将缩放机制绑定到一个简单的鼠标滚轮侦听器 graph.addMouseWheelListener(新的MouseWheelListener(){ @凌驾 公共空鼠标滚动(MouseEvent e){ 如果(e.计数,java,user-interface,swt,zest,Java,User Interface,Swt,Zest,注意:我没有包括导入内容如果您认为答案解决了问题,请单击绿色复选标记将其标记为“已接受”。这有助于将注意力集中在仍然没有答案的旧帖子上。如果您认为答案解决了问题,请单击绿色复选标记将其标记为“已接受”。这有助于保持对仍然没有答案的旧帖子的关注。感谢awnser,我实际上设法让它与复合和SashForm混合使用,并在完成后发布代码。感谢awnser,事实上,我成功地将它与复合和SashForm混合使用,并将在完成后发布代码。这实际上不起作用。是的,图形可以滚动,但是它从GridLayout中获得分
Graph graph = new Graph(shell, SWT.H_SCROLL | SWT.V_SCROLL);
public class ZoomableZestGraph extends Composite {
private GraphViewer graphViewer;
private Graph graph;
public ZoomableZestGraph(Composite parent, int style) {
super(parent, style);
this.setLayout(new GridLayout(1, true));
this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,1));
//create a GraphViewer and Graph
graphViewer = new GraphViewer(this, SWT.V_SCROLL | SWT.H_SCROLL);
graph = graphViewer.getGraphControl();
graph.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
graph.setHorizontalScrollBarVisibility(Graph.ALWAYS);
graph.setVerticalScrollBarVisibility(Graph.ALWAYS);
//Fill our graph with some nodes and connect them
GraphNode node1 = new GraphNode(graph, SWT.NONE, "Earendil");
GraphNode node2 = new GraphNode(graph, SWT.NONE, "Elros");
GraphNode node3 = new GraphNode(graph, SWT.NONE, "Elrond");
GraphNode node4 = new GraphNode(graph, SWT.NONE, "Elladan");
GraphNode node5 = new GraphNode(graph, SWT.NONE, "Elrohir");
GraphNode node6 = new GraphNode(graph, SWT.NONE, "Arwen");
new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1, node2);
new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1, node3);
new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node2, node4);
new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node2, node5);
new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node2, node6);
/*
This graphViewer consists of 2 components: the control and the graph (Figure)
We want to give the control a size by the layout and the graph a custom, bigger value.
For the control (graphViewer.getControl) I simply grab all available space
*/
GridDataFactory.fillDefaults().grab(true, true).applyTo(graphViewer.getControl());
//For the graph we have to create a PaintListener.
graph.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
graph.setSize(1300, 1080);
}
});
//The Graph now fills the shell/parent composite,
//but the actual graph size can be set as we want in the paint //listener
//Zooming with the class org.eclipse.gef.editparts.ZoomManager
//As arguments we need a ScalableFigure which we receive by graph.getRootLayer and the Viewport.
ZoomManager zoomManager = new ZoomManager(graph.getRootLayer(), graph.getViewport());
//we bind the zoom mechanic to a simple mouse wheel listener
graph.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
if (e.count < 0) {
zoomManager.zoomOut();
} else {
zoomManager.zoomIn();
}
}
});
//We give the focus to our graphViewer, so it receives the MouseWheel Events
graphViewer.getControl().forceFocus();
}
@Override
protected void checkSubclass() {
//we are a composite subclass
}
}