这里应该有用过Jgraph的筒子吧,求帮忙啊!
我的问题是当我光标移动的Jgraph里的一个Cell上时,我想让它显示一个JToolTiptext
但不显示,而当我的光标离开那个Cell时,设置的JToolTiptext却出现了!弄了几天了,
都不知道是什么问题,求大大们帮忙啊,谢谢了!
一下就是那个测试代码:
import java.awt.Color;import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.Rectangle2D;import javax.swing.JFrame;
import javax.swing.JScrollPane;import javax.swing.ToolTipManager;import org.jgraph.JGraph;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;public class Hello {
public static void main(String args[]){
GraphModel model = new DefaultGraphModel();
//视图
GraphLayoutCache view = new GraphLayoutCache(model,new DefaultCellViewFactory());
//通过模型与视图创建图形
final JGraph graph = new JGraph(model,view);
//图形上的单元[单元包括:顶点,边,结点]
DefaultGraphCell dgc=new DefaultGraphCell("Hello");
GraphConstants.setBounds(dgc.getAttributes(),new Rectangle2D.Double(20,20,40,20));
//设置梯度颜色[即由白色到设置颜色的一个过度]
GraphConstants.setGradientColor(dgc.getAttributes(), Color.orange);
GraphConstants.setOpaque(dgc.getAttributes(),true);
graph.getGraphLayoutCache().insert(dgc);
// graph.set
// mxGraphComponent.setToolTips(true)
ToolTipManager.sharedInstance().registerComponent(graph);
ToolTipManager.sharedInstance().setInitialDelay(0);
JFrame frame = new JFrame("Tool Tip Demo");
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane js=new JScrollPane(graph);
frame.getContentPane().add(js);
frame.pack();
frame.setVisible(true);
graph.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseMoved(MouseEvent e){
Object o=graph.getFirstCellForLocation(e.getX(), e.getY());
if(o==null)//如果不在光标不在Cell上就不显示提示
return;
else
{
if(o instanceof DefaultGraphCell)
graph.setToolTipText(o.toString());
}
}});
}
}
我的问题是当我光标移动的Jgraph里的一个Cell上时,我想让它显示一个JToolTiptext
但不显示,而当我的光标离开那个Cell时,设置的JToolTiptext却出现了!弄了几天了,
都不知道是什么问题,求大大们帮忙啊,谢谢了!
一下就是那个测试代码:
import java.awt.Color;import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.Rectangle2D;import javax.swing.JFrame;
import javax.swing.JScrollPane;import javax.swing.ToolTipManager;import org.jgraph.JGraph;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;public class Hello {
public static void main(String args[]){
GraphModel model = new DefaultGraphModel();
//视图
GraphLayoutCache view = new GraphLayoutCache(model,new DefaultCellViewFactory());
//通过模型与视图创建图形
final JGraph graph = new JGraph(model,view);
//图形上的单元[单元包括:顶点,边,结点]
DefaultGraphCell dgc=new DefaultGraphCell("Hello");
GraphConstants.setBounds(dgc.getAttributes(),new Rectangle2D.Double(20,20,40,20));
//设置梯度颜色[即由白色到设置颜色的一个过度]
GraphConstants.setGradientColor(dgc.getAttributes(), Color.orange);
GraphConstants.setOpaque(dgc.getAttributes(),true);
graph.getGraphLayoutCache().insert(dgc);
// graph.set
// mxGraphComponent.setToolTips(true)
ToolTipManager.sharedInstance().registerComponent(graph);
ToolTipManager.sharedInstance().setInitialDelay(0);
JFrame frame = new JFrame("Tool Tip Demo");
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane js=new JScrollPane(graph);
frame.getContentPane().add(js);
frame.pack();
frame.setVisible(true);
graph.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseMoved(MouseEvent e){
Object o=graph.getFirstCellForLocation(e.getX(), e.getY());
if(o==null)//如果不在光标不在Cell上就不显示提示
return;
else
{
if(o instanceof DefaultGraphCell)
graph.setToolTipText(o.toString());
}
}});
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货