Java – how to use GridLayout to set component size? Is there a better way?

I'm using java to develop a bigger GUI, and I'm getting angry with the layout manager

I have a "settings panel" that contains a variable number of jcomponents (labels, buttons, jspinners, jsliders,...) I just want the following:

Jlabel < JComponent jlabel < JComponent jlabel < JComponent... The size of my panel is 500px, so there is enough space for a large number of components Unfortunately, GridLayout always extends the size of components to the entire panel, even if I set a maximumsize for each component If only two buttons are 250px high, it looks stupid I tried stream layout, but I couldn't find the right way I tried @ r_ 443_ 2419@Layout.Y_AXIS However, components are always centered, and labels and components are not on the same line Does anyone know a good way for layout managers to deal with this method?

Solution

An alternative to other layouts might be to place the panel in GridLayout and flowlayout. In another panel In this way, your spacing will remain the same, but will not expand throughout the available space

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>