How to make canvas with Swing?

后端 未结 4 1226
长发绾君心
长发绾君心 2020-11-27 18:58

I\'m trying to make a paint editor with Java in which I have a toolbar with the objects that I would like to paste in the canvas. I\'m using Swing components to make the GUI

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 19:31

    Simply subclass JComponent.

    JPanel is an inappropriate class. It is often suggested as it appears to have setOpaque(true) invoked on it automatically. It's actually the PL&F which does that, and whether or not it actually happens is implementation and vendor dependent.

    Canvas is a heavyweight component. That is to say that it is controlled by the underlying windowing system. The result is that it will typically be drawn over the top of Swing components, without respect to z-order or clipping (putting it in a scroll pane will give odd behaviour).

提交回复
热议问题