Jason S
Jason S

Reputation: 189806

Swing: Is there a simple way to make 1 component ignore the layout manager?

I have a JPanel with one component that I want to place in an absolute sense, whereas the rest of the components are placed according to a layout manager.

Is there a simple way to do this?

Upvotes: 2

Views: 621

Answers (3)

trashgod
trashgod

Reputation: 205865

You might also want to look at OverlayLayout, seen here. For some reason it's excluded from the conventional gallery, but it may be of interest.

Upvotes: 3

camickr
camickr

Reputation: 324147

Are you saying you want a component painted over top of all the other components? If so then you would need to use a JLayeredPane.

Why don't you post a SSCCE that demonstrates what you want to do?

You can add components to a frame as you would do normally and make the frame visible. Then you can add this random component and use setBounds on the component. As long as you don't revalidate() the panel or resize the frame we will be able to see how you intend to position this component relative to all the other components.

Upvotes: 4

meverett
meverett

Reputation: 921

You can do this with only needing one JPanel using MigLayout

Upvotes: 1

Related Questions