简体   繁体   中英

In java swings Can i draw a canvas on a canvas?

In JFrame i want to draw a canvas on a canvas and on requirement basis i want to keep either canvas1 set visible or canvas2 set visible. Can i do that?

Don't mix Swing (JFrame) with AWT (Canvas) components unless you have a compelling reason to do so, otherwise you're just asking for unusual hard to debug trouble. Instead draw on a JPanel in its paintComponent method as has been described on this site many times, and swap JPanels via CardLayout . Also, it's "Java Swing", not "java swings".

OverlayLayout所示, 在这里 ,可满足您的需求。

Since Canvas is just a subclass of Component (and sometimes of JPanel), then you can simply create two canvas boxes with absolute positioning where one is larger and behind the other. The you can use the .setVisibile(Boolean) to show/hind any one of the two.

see this link for java absolute layout http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM