我正在尝试将较小的面板 ( sub) 覆盖在较大的面板 ( parent) 上。sub 的尺寸小于 parent 的尺寸。
JPanel sub = new JPanel();
JPanel parent = new CustomPanel();
我想覆盖父级的paintComponent方法以在左上角绘制 sub ,从顶部和左侧偏移 5 个像素。它看起来像这样:
class CustomPanel extends JPanel() {
    JPanel sub = null;
    public CustomPanel(JPanel sub) {
        this.sub = sub;
    }
    @Override
    public void paintComponent(Graphics g) {
        this.paintComponent(g);
        // TODO: Here is where I would call something like sub.paint();
        // However, I want sub to "start its paint" 5 pixels inside of
        // parent's dimensions. How do I specify this?
是否可以告诉 sub 在特定位置绘制自己?可怕的想法?