カスタムJComponentを追加するときにpaintComponent(Graphics)
が呼び出されないのはなぜですか?カスタムJComponentを追加するときにpaintComponentが呼び出されない
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("Paint Component Example");
frame.setPreferredSize(new Dimension(750, 750));
frame.setLocationByPlatform(true);
JPanel panel = new JPanel();
panel.add(new CustomComponent());
frame.add(panel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
public class CustomComponent extends JComponent {
public CustomComponent() {
super();
}
@Override
protected void paintComponent(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(10, 10, 10, 10);
}
}
私は、このインスタンス内のカスタムコンポーネントを作成する必要はありません知っているが、それは私が把握することはできません別の問題の非常に単純化したバージョンです。