关于java Canvas加入JscrollPane后显示问题
public class ShowGraphic extends JFrame{
public ShowGraphic() {
// TODO Auto-generated constructor stub
StringBuffer code = Lex.getCode("c_file/BubbleSort.c");
CodeAnalysis ca = new CodeAnalysis(code);
System.out.println(code.toString());
Step head = ca.getHeadOfBubbleSortGraphics(code);
System.out.println(code.toString());
JPanel panel = new JPanel();
panel.add(new GraphicShow(head));
JScrollPane scroll = new JScrollPane(panel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
add(scroll);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingConsole.run(new ShowGraphic(), 1000, 700);
}
}
class GraphicShow extends Canvas{
Step head;
Map<Step, Polygon> polygonMap = new HashMap<Step, Polygon>();
Map<Step, Rectangle> recMap = new HashMap<Step, Rectangle>();
public GraphicShow(Step head){
this.setSize(1000, 1000);
this.head = head;
}
public void paint(Graphics g){
this.drawFlowChart(g, head, 100, 10);
}
其中drawFlowChart是画图的,head是一个有向图的引用,画出的效果如下:
可是当我拉动滑块后,一部分会消失,如下图:
什么情况?
我不用drawFlowChart方法,用g画几个图形也没有消失啊。我觉得是drawFlowChart的问题,可能改变了head的引用值,不过我检测了一下并没有改变,我肯定head没有改变值,请问那位大神对canvas比较熟悉?给解答一下?多谢!
java gui Canvas JScrollPane --------------------编程问答-------------------- 而且是第一个矩形不消失。
补充:Java , Java SE