• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the best Layout?  RSS feed

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Im looking what is the best layout to represent, a title at the top and center of window and then vertically an array with images without any gap and center alignment
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take your pick.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People are going to it isn't one, but I like to use null. Layouts are kinda hard to understand and use. You can specify EXACTLY where you want with the setBounds(int x, int y, int width, int height) method.
Here it is:
http://download.oracle.com/javase/1.5.0/docs/api/java/awt/Component.html#setBounds(int, int, int, int)
You just have to specify in the beginning:
jframe.setLayout(null);
OR
window.setLayout(null);
OR
jwindow.setLayout(null);
or whatever you are using.
For example,

Like that.
Enjoy,
cc11rocks aka John Price

EDIT: You can also do it dynamically. Here is an example:
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of us on the forum try to promote proper programming and design concepts. Using a "null layout" is not one of them.

Swing was designed to be used with layout managers. You are never restricted to a single layout manager. You can nest panels with different layout managers to get your desired effect. Maybe start with a BorderLayout. Then put the title in the NORTH and create a panel (maybe with a BoxLayout) for the images that goes in the center.

Experiment and see what happens.
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coming from web/jsp programming, it can be painful to work with Swing's layouts at first. Making something as simple as a form can be really complicated, when buttons suddenly decide to take up all available space, or when components simply flat out refuse to use their set maximum size.

The best solution I've found so far is the GroupLayout. It looks somewhat complicated at first, but its actually fairly easy to use. And it gives quite nice results.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!