Alternative solution to null layout manager when absolute positioning is needed
Asked Answered
L

1

3

Few months ago i read this Swing tutorial http://zetcode.com/tutorials/javaswingtutorial/resizablecomponent/ for understanding how implementing resizable components inside Swing.

The tutorial tells about using a null LayoutManager in order to have the possibility of absolute positioning child components.

In a discussion relative to another subject @Andrew Thompson pointed out that using null layout is a bad idea. This article http://download.oracle.com/javase/tutorial/uiswing/layout/none.html describe null layout manager as not desirable too, anyway it says that in certain situations the might be useful.

In a situation where:

  1. i need absolute positioning for a JPanel's child components
  2. i need to implement my own bounding box conditions for child components (in order to establish possible overlapping situations )
  3. i need JPanel's child component be resizable

Is correct in the described situation use a null layout manager?

Or there are other better solutions to achieve that goals using a layout manager for my JPanel container component?

thanks in advance

Louanne answered 26/3, 2011 at 13:12 Comment(0)
M
2

Your best solution would be to implement your own LayoutManager (or extend an existing one, if one is really close to your needs) using the features and controls you are looking for. Your absolute positioning requirements would simply become a method of your layout manager.

For instance, I have, in the past, followed techniques to extend FlowLayout to give it abilities to properly wrap elements when contained in a JScrollPane. Here is an example, although this is not the same one that I used.

Maintopmast answered 26/3, 2011 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.