|AnchorLayout [message #897433]
||Tue, 24 July 2012 06:56
| Ossama Nasser
Registered: July 2012
Hello this is my first post at eclipse forums so I hope you like it|
I've been thinking a lot about java swing and how it's easy to build GUIs in other IDEs (like Delphi and Visual Studio) and how hard it is (for me at least) in NetBeans and eclipse .
So it hit me : why don't I design my own layout manager that acts like the other IDEs.
But dreaming is easy, I designed the anchor layout manager and I had few problems :
What's good about it :
It uses size and location to position a visible component on the container (like absolute layout) and it uses easily defined anchors to set the problem of resizing and repositioning when the container size changes , how ?
When you add a component to the container you add an instance of the class AnchorConstrains which in turn asks you to define the anchor (Top ,Left ,Right ,Bottom and it's combinations) along with location and size ,and based on the anchors the layout define resizing and/or repositioning
Despite the layout manager changes the size of components in some cases it cannot make components smaller than minimum size or bigger than maximum size
If we define minimum size with 0 (width and/or height) the layout manager doesn't use it ,so when we reach at resizing the case where component size can be zero or event negative the layout manager takes the previous size which in this case is positively positive
And to override max size lock you simply have to make the value of maximum size either big enough to never be reached by preferred size or simply 0
I do believe that some things sound mysterious to you because I'm not that good at explaining with words but the way the layout manager works is easy and simple and I doubt you will have a problem with it
What's bad about it :
Though I searched online a lot (but not enough apparently) to know how to define the layout manger to work with windowBuilder ,I failed , so here it is how the layout manager must operate in windowBuilder :
o Like absolute and Group layouts we must be able to drag and drop components on the container defining the constrains of the location and size (anchor is set default to TOP LEFT) with the ability to change them along with anchors as the user wishes
o Anchor layout cannot be shared : windowBuilder creates a JPanel and replaces the JFrame content pane with it ,checking the parents does not work properly because the layout manager needs the size of the container so when we pass the content pane as the target the size will be (0,0) so all the calculations will be wrong
So the bottom line is I have these to problems for now ,can I count on you to help ?
I have attached the source files with a simple demo and JavaDoc
(Size: 61.60KB, Downloaded 161 times)
Powered by FUDForum
. Page generated in 0.02113 seconds