• Post Reply Bookmark Topic Watch Topic
  • New Topic

Layout Manager Question(s)

 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code :

If I change this line (getContentPane().add(cb);) to add treeStructure instead of cb my display doesn't show properly. componentBlock extends JPanel and does a few things like adding a JPanel to itself as well. Without having to post everything can anyone tell me why this isn't working by looking at the above code?
The componentBlock uses BorderLayout. I add a JLabel to a JPanel that is added to the "NORTH", a JPanel with layout GridBagLayout that has 2 JLabels added to 1,0 and 1,1 that are added to the "SOUTH", and a JPanel that has drawings on it added to "CENTER" that use BorderLayout. If I use the line above getContentPane().add(cb); everything displays but if I change it to add treeStructure instead it eliminates everything in the "CENTER" JPanel pushing the "NORTH" and "SOUTH" JPanels together with no space in between. Any help would be appreciated. Thanks.
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What NORTH and SOUTH are you talking about? We don't have time to play 20 questions.

The answer is the same as the answer to your last question.

Post your SSCCE that demonstrates the problem!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without having to post everything can anyone tell me why this isn't working by looking at the above code?

No. Thats as good as asking a mechanic to figure out whats wrong with the car, without opening the hood.

Like Rob rightly pointed out, you need to post your SSCCE code. Please do take out time to click the link and find out what SSCCE really means. One immense advantage of SSCCE is that many times, while constructing the SSCCE, you yourself will figure out what is going wrong. The code you have currently posted is useless for us. We cant download and run it ourselves because we dont know what componentBlock is. Since all of us are volunteers here, I don't think anybody is going to waste their time writing our own componentBlock based on
componentBlock extends JPanel and does a few things like adding a JPanel to itself as well
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create JPanels with different layout managers and add JPanel to JPanels shouldn't each JPanel remain it's own thing? What I'm trying to do is this :
1) create a class that extends a JPanel that draws a shape on itself (circle, cylinder, eventually more...)
2) create a class that also extends a JPanel that uses BorderLayout. At the top of the JPanel there will be a JLabel (i.e. BorderLayout.NORTH) that needs go the full length of the JPanel and acts as a header. At the bottom (i.e. BorderLayout.SOUTH) there will be a JPanel that will hold numerous JLabels that serve up information related to this JPanel.
3) create a class that will create a grid whereby I will place the step 2 JPanels (above). So these JPanels will be on row 1, row 3, row 5, etc.., and in between there will be a horizontal line showing linking up "children" JPanels with their "parents". The end result will hopefully look similar to a family tree BUT this is not intended to be a family tree as you can see from the code and I don't believe JTree can accomplish what I'm trying to do here. Any help would be greatly appreciated since I can't find a solution anywhere nor examples that look like this.

Main class


 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you change from

to

You'll see what one cell should look like.
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is still not a SSCCE. We don't care about the details of your code. Your question is not about the custom painting it is about layout managers, so create something simple that demonstrates what you are trying to do. The point is to create a simple layout using standard components to see if the layout works. Then once that works you switch to use one of your custom components. If it works great, if not then you know the problem is you custom component. So know you have a specific question to ask.

The only comment I have is that layout managers work with peferred sizes. When you do custom painting components have a 0 size unless you specifically set the preferred size or override the getPreferredSize() method to return a proper size.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!