Custom JPanels inside another JPanel.

P

pek

So I have this JPanel that I add a scroll pane to make it scrollable.
I created a class that is a subclass of JPanel, lets call it
CustomPanel. CustomPanel basically has some labels, buttons etc. What
I do is add a CustomPanel to the JPanel. What I want is that
CustomPanel should have the width of JPanel but it's own height. That
way JPanel ultimately is contains a list of CustomPanels. What the
problem is that I tried to use BoxLayout and GridLayout. Let's say
that JPanel's height is 4 times the CustomPanel's one. If I add one
CustomPanel, that will expand and use all of JPanels area. If I add
more that 5 the CustomPanels are correctly added with the correct
size. So, I can't figure out what Layout Manager to use.

Any help?
Thank you.
 
J

Joshua Cranmer

So I have this JPanel that I add a scroll pane to make it scrollable. I
created a class that is a subclass of JPanel, lets call it CustomPanel.
CustomPanel basically has some labels, buttons etc. What I do is add a
CustomPanel to the JPanel. What I want is that CustomPanel should have
the width of JPanel but it's own height. That way JPanel ultimately is
contains a list of CustomPanels. What the problem is that I tried to use
BoxLayout and GridLayout. Let's say that JPanel's height is 4 times the
CustomPanel's one. If I add one CustomPanel, that will expand and use
all of JPanels area. If I add more that 5 the CustomPanels are correctly
added with the correct size. So, I can't figure out what Layout Manager
to use.

Any help?
Thank you.

Try a FlowLayout with a vertical direction.
 
P

pek

Try a FlowLayout with a vertical direction.

Can you write me the code? Cause I cannot find where to change the
direction. The is no .setOrientation on either FlowLayout nor JPanel.
I am using java 1.6 if this helps.
 
A

Andrew Thompson

pek wrote:
...
Can you write me the code?

(shrugs) He* probably can. How much were you offering?

* I could not understand what you posted, but Joshua
seemed to.
 
P

pek

pek wrote:

..


(shrugs) He* probably can. How much were you offering?

* I could not understand what you posted, but Joshua
seemed to.

I looked for what he said and it seemed that it doesn't exist. I
wouldn't asked him to write anything if I didn't search first. After
all, I bet it's probably 3 lines of code that he knows and doesn't
need to search since he is so sure what I should do...
 
A

Andrew Thompson

pek wrote:
...
I looked for what he said and it seemed that it doesn't exist.

My bad. After not understanding the description, I failed
to carefullly read the reply, either.

Perhaps Joshua meant a BoxLayout with a Y_AXIS constraint.
<http://java.sun.com/javase/6/docs/api/javax/swing/BoxLayout.html#Y_AXIS>

But then, see 'still do not understand the question' and
that leads me to suggest that Roedy's post might contain
the path to the solution for this challenge. ;-)

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top