user2097810
user2097810

Reputation: 741

Null Layout in NetBeans-JAVA

I tried to add image to my login frame in Netbeans, so I try to change the layout from 'free Design' to 'Null Layout' (like I see in this video: http://www.youtube.com/watch?v=uZFgiqM0udA), and it's work.

But when I run the program the window open in the left side, and not in the regular size - as you can see in the picture: enter image description here

What is the problem?

Upvotes: 0

Views: 4054

Answers (4)

Jitender
Jitender

Reputation: 1

Using Absolute Layout fixed mine! For some reason, default size 0*0 was getting executed on run ( but the frame remains in custom resolution), so changing null layout to absolute is calling the custom frame size.

Upvotes: 0

Jorge Valdivieso
Jorge Valdivieso

Reputation: 1

or you can move on and start by tamming a little the layout manager.

select your frame in the navigator and then, look for this propierties

preferredSize - The size that frame will take as their default

maximumSize - The maximum size of the frame

minimumSize - Minimum size of the frame

Upvotes: 0

MadProgrammer
MadProgrammer

Reputation: 347204

Welcome to the wonderful world of why you should not use null layouts (and why learning to code a UI with a form designer is also a bad idea).

The problem you are facing is based on the fact that Swing (and AWT) were designed to work with layout managers, this is at the core of how the framework works.

When you call pack on a Window, it asks all it's children what size they would like to be and calculates the best size for the Window.

In your case, because you're not using a layout manager, the window is assuming it's default side of 0x0 (plus the frame border).

To fix the issue I suggest two things. Firstly, stop using the form designer until you understand how the UI is constructed and secondly, make use of one or more layout managers.

Take a look at A Visual Guide to Layout Managers and Using layout managers

I've not had the chance to use it, but it might also be worth while to take a look at MigLayout, it comes highly recommended by many of the users on SO

Upvotes: 4

Caffe Latte
Caffe Latte

Reputation: 1743

As far as I know, dont use null layout, use LayoutManagers instead, anyway, you're free, I think you're calling pack() method to the frame and you probably didnt set the aize of frame

Upvotes: 1

Related Questions