1 package com.badlogic.gdx.tools.flame; 2 3 import java.awt.CardLayout; 4 import java.awt.Component; 5 import java.awt.Container; 6 import java.awt.Dimension; 7 8 /** @author Inferno */ 9 public class CustomCardLayout extends CardLayout { 10 11 @Override preferredLayoutSize(Container parent)12 public Dimension preferredLayoutSize (Container parent) { 13 Component component = getCurrentCard(parent); 14 return component != null ? component.getPreferredSize() : super.preferredLayoutSize(parent); 15 } 16 getCurrentCard(Container container)17 public <K> K getCurrentCard(Container container){ 18 Component c[] = container.getComponents(); 19 int i = 0; 20 int j = c.length; 21 while (i < j) { 22 if (c[i].isVisible()) { 23 return (K)c[i]; 24 } 25 else 26 i ++; 27 } 28 return null; 29 } 30 31 } 32