简体   繁体   中英

Make components overlap in flowlayout

I am writing a small card game and so far i have the following :

  • I have a custom JPanel Card component where i override the getPreferredSize() method

  • I also have a custom HandView component which essentially just adds a bunch of card components to it. I also override the getPreferredSize() and use a flowlayout.

My problem is when too many Card components are added to the handView they are not shown. I do not want the card components and the hand component to resize . What i would like is to make the card components start overlapping each other when too many are added. Is that possible with a flowlayout?

Is that possible with a flowlayout?

You can specify a horizontal gap when creating the FlowLayout . If you use a negative value then you will get overlapping.

However, you may want to consider the Overlap Layout which was written specifically for this type of layout. It provides different option for how the overlapping should work.

What i would like is to make the card components start overlapping each other when too many are added

In both cases you would need to dynamically reset the gap as cards are added/removed and then revalidate the panel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM