I am attempting to overlay a smaller panel (sub
) over a larger panel (parent
). The dimensions of sub are smaller than that of parent.
JPanel sub = new JPanel();
JPanel parent = new CustomPanel();
I would like to override parent's paintComponent
method to draw sub in the top left hand corner with an offset of 5 pixels from the top and left sides. It would look something like this:
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?
Is it possible to tell sub to paint itself at a specific location? Terrible idea?