Make components overlap in flowlayout

白昼怎懂夜的黑 提交于 2021-01-05 06:12:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32910225/make-components-overlap-in-flowlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!