Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why can't I adjust my buttons location in the frame?  RSS feed

 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. I can't seem to reallocate my buttons location with the current program format. I do not wish to use grid bag layout as I would attach some images and will be changing their location at some point of time.

I'm using setBounds.

Can someone help me understand why is that so? The program I've attached is a small portion of it.



Thanks in advance.

Best Regards
Adrian Lee
[ July 02, 2007: Message edited by: Adrian Lee ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are adding them to a JPanel sub2, which defaults to a FlowLayout.
setBounds requires the LayoutManager to be null
JPanel sub2 = new JPanel(null);

but a null layoutManager will cause you more problems later.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, Thanks for your reply. It works. But as you have mentioned "layoutManager will cause you more problems later."

Can you enlighten me on what kind of problems would occur? Thanks alot.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there's a whole bunch of 'user' options the layoutManager takes into
consideration - fonts/resolution etc, but perhaps resizing the application is
the stand-out difference.

run your program, now drag the right border to where it cuts off half the buttons.
this is not good.

remove the null, and recompile the code you posted. now drag the
right border to the left - notice the layoutManager 'managing' the positioning
of the buttons
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!