Drawing rectangles on a JPanel

后端 未结 3 1249
生来不讨喜
生来不讨喜 2020-12-04 03:01

I have a JScrollPane and on top of it I have a JPanel named \'panel1\'. I want some rectangles to be drawn on this JPanel.

I have a class named DrawRectPanel which e

3条回答
  •  再見小時候
    2020-12-04 03:20

    instead of adding

    contentPane.add(new DrawRectPanel());
    

    you should do

    contentPane.add(panel1);
    

    Because you already have new DrawRectPanel in panel1. But in your code you are adding another instance of DrawRectPanel in contentPane. And never added panel1 in none of your container.

提交回复
热议问题