12 Replies - 915 Views - Last Post: 02 April 2011 - 02:18 PM Rate Topic: -----

#1 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Layout managers are horrible.

Posted 02 April 2011 - 12:02 PM

Hello everyone i have to make a final project in college and we aren't allowed to use null layouts(i think) So i went and grabbed a copy of net-beans and made a nice panel with the grouplayout. I then ran the code and re sized the form.

Only 2 components are making themselves use up the new amount of space the rest are acting just like they would if it was a null layout...

What I'm trying to say here is java sucks at GUI's.

your not allowed to use null because it might not fit on peoples screens, and layout managers don't stretch the components correctly so its better to just make re-sizable false. In the end layout managers are no different then null. Just make the window fit in a 640x480 screen to make it comparable for everyone...

Sorry guys i'm raging i need someone to explain to me how to make a gui look exactly like i want like i would with null layout only not using a null layout...

This post has been edited by giuseppe105: 02 April 2011 - 12:07 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Layout managers are horrible.

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 12:30 PM

For your thing I would use a JPanel with BorderLayout

In the CENTER region I would put a JPanel with a GridLayout(4, 2)
fill this JPanel with 8 JLabel representing your text

In the SOUTH region a Box.createHorizontalBox() into which I'll put:
- an Horizontal Glue
- the JButton
- an Horizontal Glue
Was This Post Helpful? 0
  • +
  • -

#3 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 12:39 PM

so your telling me that its ok to put panels inside panels to get the result? even if its like 5 panels with 5 different layout managers?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 12:50 PM

View Postgiuseppe105, on 02 April 2011 - 02:39 PM, said:

so your telling me that its ok to put panels inside panels to get the result? even if its like 5 panels with 5 different layout managers?

Yes Sir and actually this is the trick
You can have sometimes several level of JPanel
To make somethink like

-----------
|  X  |Y|Z|
-----------



I would use a GridLayout(1, 2);
Put a JPanel with X
then another JPanel GridLayout(1,2)
with a Jpanel Y and a JPanel Z

Quite rare that you cannot achieve the result you want with a combination of JPanel BorderLayout and multiple GridLayout containning sometimes other JPanels with GridLayout

Box.createHorizontalBox() and Box.createVerticalBox() are also usefull

Actually this is the 3 elements I always use
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 01:00 PM

Think of a Sudoku grid

It is composed of a JPanel GridLayout(3,3) containing 9 Region Panel
The Region JPanel are composed of a GridLayout(3,3) containing 9 Cell Panel
The Cell panel are composed of a CardLayout containing:
- or a JPanel GridLayout(3,3) to show the number 1 to 9
- or a JPanel containing the selected number
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10477
  • View blog
  • Posts: 38,835
  • Joined: 27-December 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 01:14 PM

GroupLayout was actually designed for GUI Builders. While you can hand-code it, I wouldn't advise using it. Straight from the documentation:

Quote

GroupLayout is intended for use by builders, but may be hand-coded as well


In my experiences, a combination of BorderLayout, BoxLayout, FlowLayout, and GridLayout have been sufficient.

You might want to start with the Oracle Tutorial on LayoutManagers, as well as the Swing tutorials in the Java Tutorials section on DIC.

Hope this helps some. :)
Was This Post Helpful? 1
  • +
  • -

#7 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 01:15 PM

i always made null layouts so i didn't know that it was ok to make huge confusing messy panels inside panels to get the result. I still think layout managers are bad. java needs to make a better alternative to this.
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10477
  • View blog
  • Posts: 38,835
  • Joined: 27-December 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 01:19 PM

It all depends on how you organize your code. My rule of thumb is if a Component warrants its own method in another GUI Component class to set it up, then it probably warrants being subclassed for better encapsulation. Once you get used to the LayoutManagers, it makes the null layout seem like a lot more work. From the sounds of things, you'll probably get along well with the .NET guys, as they have it easy with their GUI Builder, which actually produces more maintainable code. :)
Was This Post Helpful? 1
  • +
  • -

#9 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 01:22 PM

How do i make everything spaced nicely instead of being crammed all over the place
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10477
  • View blog
  • Posts: 38,835
  • Joined: 27-December 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 01:25 PM

FlowLayout does this by default. Just set FlowLayout as the LayoutManager for the Container and add the JComponents.

If you have a more specific layout in mind, we will be happy to advise a more specific solution if you can upload a mockup or some visual. :)
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 01:47 PM

View Postgiuseppe105, on 02 April 2011 - 03:22 PM, said:

How do i make everything spaced nicely instead of being crammed all over the place

With FolwLayout ? just add some new JLabel(" ")
In a Box there are Glue and Strut
Was This Post Helpful? 1
  • +
  • -

#12 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 02:14 PM

ok guys thanks for the help i think i can manage the tweaking of spacing.

Right now the application is just a bunch of java files that aren't attached in any way.

I'm going to see how far i can get today.

Thanks for the help ill post back on this topic if i run into more trouble related to layout managers.

I read somewhere on the internet of a new layout Manager called the MigLayout just thought i should mention it.
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10477
  • View blog
  • Posts: 38,835
  • Joined: 27-December 08

Re: Layout managers are horrible.

Posted 02 April 2011 - 02:18 PM

Glad we could help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1