Why is paintComponent executed 2 times?
问题 I have following code: canvas=new MembershipFunctionComponent(functions); canvas.setPreferredSize(new Dimension((int)this.getWidth(), (int)this.getHeight())); canvas.addMouseListener(canvas); pane.add(canvas); MembsershipFunctionComponent extends JComponent. Why is paintComponent method executed 2 times? 回答1: paintComponent can get called at pretty much any time by the Swing framework. Examples of when this might happen: Any time a component is resized Any time part of the component is