0
votes

I know this has been asked alot and in various ways, and I have tried them, but with no success. i am using netbeans and swing to create my GUI.

i have a Jlabel inside of a JPanel. Whenver I place the label inside the panel, it automatically anchors it to the closest component which is NOT what I want. I want to center the component, regardless of size.

However, creating custom JPanels in the "Code" section of the GUI editor to make a BoxLayout and GridBagLayout does not seem to work. It seems no matter what, it still anchors. You can see the attached jpg of what it is doing in my editor.enter image description here

Anybody have some ideas?

As mentioned, I have tried to change the "Custom Creation Code" of the JPanel to do: new javax.swing.JPanel(new GridBagLayout());

and then removed the parent tag of my JLabel and added "Post-Creation Code" to be: statusPanel.add(versionLabel,new GridBagConstraints());

I have also tried typing out the GridBagConstraints to say centered.

1

1 Answers

1
votes

Get a copy of NetBeans 7.0 They've just completely overhauled their GridBagLayout Visual Designer

You should be able to achieve this quite handily with it.