How to disable automatic component alignment in Netbeans?
Asked Answered
K

5

5

Is there any way or plug-in that disables Netbeans automatic component alignment? When I place a label, all my components got placed randomly on the panel, not how I set them up. Every time I add a component the window gets re-sized or some component does.

Kaiak answered 28/12, 2011 at 18:3 Comment(0)
R
3

Choose a layout other than the default, GroupLayout. Better, do a few manually to get the idea, as suggested in A Visual Guide to Layout Managers.

Addendum: @Paul argues persuasively against using a GUI editor. While I tend to agree, I see two reasonable use cases:

  • For the novice: a convenient way to experiment with less familiar layouts.
  • For the experienced developer: a way to manage that one difficult layout that you just know will change, as suggested here.
Romeoromeon answered 28/12, 2011 at 18:8 Comment(3)
How can I choose a different layout?Kaiak
Right-click on the desired container in the Inspector menu.Romeoromeon
Thanks! I will poke around with these layouts and experiment.Kaiak
T
3

As a long-time NetBeans user (over 11 years now...geez, I'm getting old) and as someone who's worked exclusively in Swing for over half that time I think I'm qualified to give you the following advice:

Don't use a WYSIWYG UI editor.

Unless your whipping out a simple UI with a button and a text field for your own use you're better off in the short term (development) and the long term (maintainability) if you create your UIs by hand. It's not that hard if you do a little thinking beforehand.

The layout managers I've found to be most useful are BorderLayout, FlowLayout, GridLayout, and my particular favorite, BoxLayout (including the handy Box component).

While I haven't used it myself, I've heard good things about the MiG layout manager, which has a nice quite start guide.

If you have questions on using any of the layout managers that the many tutorials don't answer (overview of layout managers with links to tutorials) , just post them at SO.

Tomkin answered 28/12, 2011 at 18:20 Comment(3)
That's a great advice, but what's wrong with using a GUI editor to position the components? I know the code can get pretty messed up after the generation of the components, but it's still code-able. I so far don't have any idea how to manually position components manually.Kaiak
What's wrong with using the GUI editor? Well, I thought that would be self-evident based on your question :) Java layout managers exist to move things around, unlike Windows development for example, where components generally stay where you put them. This is known as absolute positioning - Java will do this but it's rarely done in my experience (see Doing Without a Layout Manager). The code you write yourself will be much cleaner and easier to maintain, and it's not that hard to do... (see next comment)Tomkin
There are two "tricks" to laying out your own UI: build it with nested panels, and during development set the background color of each panel to a different color so you can see which panel is where. If your outer panelTomkin
E
3

In Netbeans, the first thing you do when making a GUI is drag the GUI container box to the right size you want, then add a panel to the inside of your GUI container box and stretch it out to fit the container box. This main Panel is where you drag all your labels, textBoxes, and components to.

To stop the auto aligning, just right click on that main panel, and go to Set Layout, and choose Null Layout.

That should do the trick!!!

You can do it later on in your project when you run into the auto align problem, it doesn't have to be at the start of your project.

Expect answered 3/11, 2013 at 23:51 Comment(0)
C
0

I am also working with the "WYSIWYG UI editor" in Netbeans. After i testet the last answer, i have to correct this. If you set "Set Layout" to "Null Layout" it can happen, that all your compnents get lost. Better way is to set it to "Free Design", but the fear still remains.

Caseycash answered 8/3, 2017 at 13:54 Comment(1)
I'm using Netbeans 8.2 for Windows and my components remained in my jPanel, nothing got lost. What sometimes happens is that the jPanel gets rezised to zero, so it just needs to be resized again to see its components.Fee
K
0

In using netbeans to design your GUI application, set the Layout of the JFrame to Free Design. Drag a panel onto the JFrame and set it Layout to Null Layout. Now you can freely design your GUI without any embarrassment.

Kerril answered 20/1, 2019 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.