> Currently I have a CardGroupPanel that extends JScrollPane (because I
> want it to be scrollable).
[quoted text clipped - 35 lines]
> I hope everything is clear. Thank you.
> Sorry for my English.
I think you could use GridLayout, GridBagLayout or nested BoxLayouts.
'Container' is not a good name for your custom GUI class because it is
the name of a basic API class of java.awt package.
> Currently I have a CardGroupPanel that extends JScrollPane (because I
> want it to be scrollable).
CardGroupPanel should extends JPanel, and be put into a JScrollPane,
rather than extending JScrollPane
> This CardGroupPanel has a JPanel named Container. The Container has a
> number of CardLabels that are components that extend JLabel and draw a
> Playing Card. CardGroupLabel also has a LinkedList<Card> cards.
Depending on how you draw the card, you should either use a standard
JLabel, and use setIcon to set the image, or you should extends
JComponent instead of JLabel.
> CardGroupPanel has a method addCards(LinkedList<Card> someCards) which
> adds someCards to cards and creates for each Card a CardLabel
> (basically a wrapper for each Card) which then is added to Container.
Your method would be better to take a Collection<Card> instead of
LinkedList<Card>
> CardGroupPanel also has an option for Card Orientation (Horizontal or
> Vertical). Depending on the orientation, the cards are drawn
> accordingly.
Most Components have orientation built in. See <http://java.sun.com/
j2se/1.4.2/docs/api/java/awt/
Component.html#setComponentOrientation(java.awt.ComponentOrientation)>
> Suppose that I create a CardGroupPanel with Horizontal orientation.
> The CardGroupPanel has width 200 (depends from the size of the
[quoted text clipped - 7 lines]
> Vertical orientation, I would like to create a second column of cards
> and activate the horizontal scroll bar.
If you follow the very first suggestion I gave you, that should solve
your problem, or at least get you moving in the right direction.
> The problem is that by default, the size of Container is not set.
> Calling container.getSize(), container.getMinimumSize() and
[quoted text clipped - 9 lines]
> I hope everything is clear. Thank you.
> Sorry for my English.
Mark Space - 15 Jul 2007 07:06 GMT
>> CardGroupPanel has a method addCards(LinkedList<Card> someCards) which
>> adds someCards to cards and creates for each Card a CardLabel
>> (basically a wrapper for each Card) which then is added to Container.
> Your method would be better to take a Collection<Card> instead of
> LinkedList<Card>
or maybe just an array?
addCards( Card [] someCards ) { // ...
pek - 15 Jul 2007 16:22 GMT
> On Jul 14, 7:23 pm, pek <kimwl...@gmail.com> wrote:> Currently I have a CardGroupPanel that extends JScrollPane (because I
> > want it to be scrollable).
>
> CardGroupPanel should extends JPanel, and be put into a JScrollPane,
> rather than extending JScrollPane
I extend JScrollPane because the scrollability of the object is not
optional. It always exist. So, rather than setting for every
CardGroupPanel a new JScrollPane, I find it much easier to extend
JScrollPane. Although, I did have some problems with the background.
When extending a JPanel, you can use setOpaque(false) and the JPanel
is transparent. When extending the JScrollPane, even if you set both
(or any combination) JScrollPane's setOpaque and the JPanel's
container setOpaque it still isn't transparent. I'd hate adding to the
constructor a Color which would be used to set it's background color.
I find it bad practice. But, this would be my solution if nothing else
doesn't work. Also, I tried overriding JScrollPane's
setBackground(Color bg) and after calling super.setBackground(bg) I
try to call container.setBackground(bg) but container hasn't been yet
initialized and a NullPointerException is been thrown. I haven't yet
found I way so please advise. ;)
> > This CardGroupPanel has a JPanel named Container. The Container has a
> > number of CardLabels that are components that extend JLabel and draw a
[quoted text clipped - 3 lines]
> JLabel, and use setIcon to set the image, or you should extends
> JComponent instead of JLabel.
I find it quicker to use JLabel since it has a setIcon. That is
currently what I use. But recently I changed it and I am overloading
the paint(Graphics g) method because I draw some more things on top of
the card. I haven't look to use JComponent yet. I think that since I
am using paint, there is no reason to be a JLabel any more. At first,
I thought that MouseListener is the reason why I still have JLabel. I
just saw JComponent at the API. It supports MouseListener. So probably
I'll change it.
> > CardGroupPanel has a method addCards(LinkedList<Card> someCards) which
> > adds someCards to cards and creates for each Card a CardLabel
> > (basically a wrapper for each Card) which then is added to Container.
>
> Your method would be better to take a Collection<Card> instead of
> LinkedList<Card>
You mean, the field should be a Collection, but when I initialize it I
would use LinkedList<Card> ? Like : Collection<Card> cards = new
LinkedList<Card>(); OK, I'll do it.
> > CardGroupPanel also has an option for Card Orientation (Horizontal or
> > Vertical). Depending on the orientation, the cards are drawn
[quoted text clipped - 3 lines]
> j2se/1.4.2/docs/api/java/awt/
> Component.html#setComponentOrientation(java.awt.ComponentOrientation)>
Never thought of using the components orientation. ;) I thought it
would be easier to create a new. But OK, I find it reasonable. ;)
> > Suppose that I create a CardGroupPanel with Horizontal orientation.
> > The CardGroupPanel has width 200 (depends from the size of the
[quoted text clipped - 10 lines]
> If you follow the very first suggestion I gave you, that should solve
> your problem, or at least get you moving in the right direction.
I'll try most of the things and send feedback here. Thank you very
much for your time.
> > The problem is that by default, the size of Container is not set.
> > Calling container.getSize(), container.getMinimumSize() and
[quoted text clipped - 9 lines]
> > I hope everything is clear. Thank you.
> > Sorry for my English.
Daniel Pitts - 15 Jul 2007 19:39 GMT
> > On Jul 14, 7:23 pm, pek <kimwl...@gmail.com> wrote:> Currently I have a CardGroupPanel that extends JScrollPane (because I
> > > want it to be scrollable).
[quoted text clipped - 17 lines]
> initialized and a NullPointerException is been thrown. I haven't yet
> found I way so please advise. ;)
If you don't set the CardGroupPAnel as the viewport view for your
scroll pane, you aren't going to get any scroll bars.
The proper way to do what you are trying to do:
CardGroupPanel panel = new CardGroupPanel();
JScrollPane scrollPane = new JScrollPane(panel);
panel.setBackground(Color.green);
scrollPane.setBackground(Color.green);
Make sure CardGroupPanel extends JPanel and implements Scrollable.
That should give you the control you need over width/height/scroll
area.
Read the sun tutorial for more information <http://java.sun.com/docs/
books/tutorial/uiswing/components/scrollpane.html>
>This CardGroupPanel has a JPanel named Container.
Not a wise choice of name. Container is the name of a the class for a
Swing getContentPane.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com