Using a layout to add a component on another component

Hi,

I'm trying to create a specific layout and I don't seem to manage.

I have a JPanel, and I want it it to have 2 component:

A component that will spread in the JPanel, and a JButton that will hover over the first component in a static position.

I known I can use the panel without a layout manager, but then each time the JPanel size changes, the first component won't spread.

Is there a layout that can help me in this? Or is there a way to do it?

Thanks!

Yoav

[515 byte] By [ymoran00a] at [2007-11-27 8:15:17]
# 1
Hello Yoav,you could attach a ComponentListener to your panel, and each time it is resized reset the size of your "first component" as well.RegardsJ鰎g
Joerg22a at 2007-7-12 20:00:02 > top of Java-index,Desktop,Core GUI APIs...
# 2
I see.Isn't there anything that does that automatically?I know that CardLayout() adds two components one over another, but just changes the visibility of the components.Isn't there something that just doesn't change the visibility?
ymoran00a at 2007-7-12 20:00:02 > top of Java-index,Desktop,Core GUI APIs...
# 3

I've tried using Component Listener.

Something isn't right.

The code looks like that:

I''ve written this in the constructor of the JFrame:

m_outerPanel = new ADPanel();

m_outerPanel.add(m_innerPanel);

m_outerPanel.addComponentListener(new MyComponentListener());

m_innerPanel.setBounds(m_outerPanel.getBounds());

and then added this class:

public MyComponentListener extends ComponentAdapter {

@Override

public void componentResized(ComponentEvent componentevent) {

Rectangle bounds = componentevent.getComponent().getBounds();

m_innerPanel.setBounds(bounds);

}

}

It seems that the inner panel is smaller than the outer panel. Any idea why?

ymoran00a at 2007-7-12 20:00:02 > top of Java-index,Desktop,Core GUI APIs...
# 4

Ok, I managed to create null layout.

Now the two components are one on top of the other - but there's still a problem.

Once one of the components receive the focus, it moves in fromt of the other. But I need the button to be on top of the first panel - no matter what.

How can I bypass that?

ymoran00a at 2007-7-12 20:00:02 > top of Java-index,Desktop,Core GUI APIs...
# 5
Solved it myself.I used setComponentZOrder() to solve this.
ymoran00a at 2007-7-12 20:00:02 > top of Java-index,Desktop,Core GUI APIs...