开发者

Java LayoutManager: Looking for a LayoutManager similar to GTK's horizontal and vertical boxes

开发者 https://www.devze.com 2023-03-06 12:36 出处:网络
Okay, I spoiled myself by playing around with GTK layouts, and now I\'ve started thinking about windows layouts in GTK\'s terms and can\'t find an appropriate LayoutManager to use.

Okay, I spoiled myself by playing around with GTK layouts, and now I've started thinking about windows layouts in GTK's terms and can't find an appropriate LayoutManager to use.

I'm specifically looking for a LayoutManager written in Java, fo开发者_运维技巧r use in a Swing-based application that acts almost exactly like GTK's Horizontal and Vertical boxes.

In particular, I want the child widgets fixed to the off-axis size of the container, and also the option to have certain components take up the extra space (the "expand" option in GTK) while the other widgets only take up their minimum on-axis size.

Is there a layout manager that will do this?


In Java, the most configurable layout manager is the GridBagLayout manager. It allows you to specify the position in a grid using gridx and gridy and how extra space is allocated along that axis using weightx and weighty.

GridBagLayout is quite fiddly, so I would suggest reading a tutorial before using, but I have never found a layout I couldnt build with GridBagLayout.


You should use nested layouts. If you understand the grid box flow border layouts in java which is easy then you can nest them to make anything you want. i would give you some java code to do it if i understood how you want to layout your components. By the way you may want to try mig layout http://www.miglayout.com/ . I don't use it my self because i all ready know how to use swing layouts but its a nice library.


You can use BoxLayout - Oracle tutorial - and javax.swing.box for a component with BoxLayout.

It can manage Vertical and Horizontal layouts.


While I've not used GTK myself the way you describe it sounds like the requirements to which I implemented MSBLayout:

http://msblayout.sourceforge.net/javadoc/de/winterdrache/layout/MSBLayout.html

It combines the properties of BoxLayout and GridBagLayout that other posters have already mentioned, but it is much easier to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消