Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BorderLayout

 
Ross McManus
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to do this.





So far I have got the buttons but they are on the top and I need them to be on the left hand side. I have tried changing the borderlayout from NORTH to EAST but it stays the same.





Can anyone tell me where I am going wrong?

The code I have so far is.









 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be adding Components without giving a location (eg EAST, WEST). Have a look at the Java™ Tutorials section. I suspect you want a different Layout, maybe Grid.

Moving to our GUIs forum, where we usually discuss this sort of thing.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are also adding things before you set the Layout. That is probably a mistake. Set the Layout first.
 
Ross McManus
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

So would I have something like.


 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite. That would be using a GridLayout, but then adding the component with a BorderLayout constant, which is irrelevant to a GridLayout.

You need to give your main panel a BorderLayout, and your sub-panel a GridLayout. Then add the sub-panel to the main panel (with position BorderLayout.WEST), and the buttons to the sub-panel (they don't need a constant).

 
Ross McManus
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

I'm not sure I understand how to do that 100% but am I anywhere near with this.


 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ross McManus wrote:Thanks.

I'm not sure I understand how to do that 100% but am I anywhere near with this.




You are adding the Buttons JPanel to two components and this is won't work. You may benefit greatly by reading the tutorial more and doing less guessing. It's all in there.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Going through my earlier post in more detail:

"You need to give your main panel a BorderLayout, ..."
"...and your sub-panel a GridLayout."
"Then add the sub-panel to the main panel (with position BorderLayout.WEST), ..."
"...and the buttons to the sub-panel (they don't need a constant).

Going through the Sun tutorial in detail is a good idea, though. Otherwise you're going to have this problem every time you have a different layout.
 
Ross McManus
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the detailed reply, I have the buttons done now.

I also have done the text in the grid that I have to do but have one question about it.

I have managed to get the text in a grid layout for that but I'm not sure how to get the black lines that divide them up on if you know what I mean like it shows in the picture in my first post.

This is what mine looks like.




This is the code I have for that part.



Also when I run it the box is small unless I drag and expand it to make it look the normal size, Is there any way to set it so it is the right size when I run it?
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the documentation for the setBorder method (and the BorderFactory class). The method belongs to the JComponent class, so borders can be applied to any Swing components - including labels.

For the size - you can use setSize on your top-level component (probably a JFrame?) before you make it visible.
 
Robert Staniforth
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, i'm doing the same thing as Ross and i've got stuck too..
It looks like they have two grids for the different types of rooms, as you see the Meeting Rooms are bigger than the Double rooms and they have a separate border. is it possible to have two grids in one area? I was trying to put two grids in BorderLayout.CENTER but it failed completely
how do you do this? i'm completely baffled

-edit
in my search to find the answer I read about JTables, is it possible they have this in a table?
i don't know Java that well but my theory was put a 2 row (1 column) table with a grid in the top for the single/double rooms and another grid with the meeting rooms in the bottom.. is that possible?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic