An alternative solution for a zero layout manager when absolute positioning is required

A few months ago, I read this Swing tutorial http://zetcode.com/tutorials/javaswingtutorial/resizablecomponent/ to understand how to implement mutable components inside Swing.

The tutorial talks about using an empty LayoutManager to be able to absolutely position child components.

In a discussion on another subject, @ Andrew Thompson noted that using a null layout is a bad idea. In this article http://download.oracle.com/javase/tutorial/uiswing/layout/none.html to describe the zero-layout manager as undesirable too, in any case, he says that in certain situations it can be useful.

In a situation where:

  • I need absolute positioning for child JPanel components.
  • I need to implement my own constraint framework conditions for child components (to establish possible overlap situations)
  • I need the JPanel child component to change.

Is the zero layout manager used correctly in this situation?

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

early

+3
source share
1 answer

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

For example, in the past, I used FlowLayout extension methods to enable elements to properly wrap when they are contained in JScrollPane . Here is an example , although this is not what I used.

+2
source

Source: https://habr.com/ru/post/912415/


All Articles