NetBeans, GUI builder (group layout) centering a component?

If you want your component to remain centered in its container if the container is resized, you have several options available to you, but I don't think that GroupLayout is one of them (please correct me if I'm wrong). One way is to change the container's layout to GridBagLayout, and then simply add the JButton into it without any constraints.

The case (i think it is very frequent) is that you have a form with many controls. The layout of the controls makes the GroupLayout a perfect choice. Except for the button at the end, that should be centered.

Of course I can put a JPanel at the end of the page, make it horizontally resizable and put into its (default) centered FlowLayout the JButton. But the question arises from the fact that in other GUI builders (not so sophisticated) like Delphi's one, the centering is a birllant extension of anchoring logic. Not anchoring a control to anywhere means let it "float" at the center.

– AgostinoX Oct 10 at 11:59 @AgostinoX you will have a lots of surprise with this LayoutManager Pete +1 – mKorbel Oct 10 at 12:04 @mKorbel, i'm not so glad to hear that :-). Can you provide a few samples? – AgostinoX Oct 10 at 12:10 for what, about what 1) check Hovercraft Full Of Eels history, he loves this LayoutManager 2) I know that childish but basic examples from download.oracle.Com/javase/tutorial/uiswing/layout/index.

Html shows all possible :-), 3) java2s. Com/Tutorial/Java/0240__Swing/1460__GridBagLayout. Htm, 4) java2s.

Com/Tutorial/Java/0240__Swing/…, – mKorbel Oct 10 at 12:15 @AgostinoX this topic Centering JComponent is solved lots of times on this forum, – mKorbel Oct 10 at 12:18.

Try another LayoutManager! GroupLayout is very obscure when just looking at the code generated by NetBeans. If you used DesignGridLayout then what you need is as simple as: DesignGridLayout layout = new DesignGridLayout(container); layout.row().center().

Add(okButton).

– AgostinoX Oct 10 at 12:39 There's no need for a GUI builder when using designGridLayout, that's its force! The code you write directly expresses the layout you want. And just reading the code gives you an immediate vision of the obtained layout.

No GUI builder, no ugly or complex code generation, that eases maintenance a lot, in addition to easing initial coding. DesignGridLayout API is very easy, you can understand how to use it and make your own layouts after only one or two hours reading the introduction and the examples on the web site. – jfpoilpret Oct 10 at 12:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions