Alternative solution to null layout manager when absolute positioning is needed
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:
- i need absolute positioning for a JPanel's child components
- i need to implement my own bounding box conditions for child components (in order to establish possible overlapping situations )
- 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 c开发者_运维问答omponent?
thanks in advance
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.
精彩评论