0

sub大きなパネル ( ) の上に小さなパネル ( )を重ねようとしていparentます。サブの次元は親の次元よりも小さいです。

JPanel sub = new JPanel();
JPanel parent = new CustomPanel();

paintComponent親のメソッドをオーバーライドして、左上隅にサブを描画し、上辺と左辺から 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?

特定の場所で自分自身をペイントするようにサブに指示することは可能ですか? ひどい考え?

4

1 に答える 1