I would use a JScrollPane in Java Swing to contain a Panel filled with other panel. I've created my JPanel and I filled it with 6 other panels, which represent a card in a game board. Then I've created my JScrollpane and I set my JPanel as a new viewport but in runtime the scrollbars don't appear and my JPanel is cut and JScrollPane shows only 4 cards on 6. Obviously i've checked my big panel's size and it is greater than the JScrollPane's but it doesn't work.
Double politicRelX=0.0686275;
Double politicRelY=0.39726;
Dimension politicDim=//dimension of my JScrollPane
JScrollPane scrollCards=new JScrollPane();
scrollCards.setBounds(//politicDimBounds);
playerTab.add(scrollCards);
JLabel politicsCards=new JLabel();
politicsCards.setName("politicsCards");
politicsCards.setLayout(null);
int dinstanceX=(int)(0.028634*politicDim.width);
int dinstanceY=(int)(0.02395*politicDim.height);
int space=(int)(0.028634*politicDim.width);
Dimension cardDim=new Dimension(//cardDimension);
for(int i=0;i<player.getCardsOwned().size();i++){
JPanel card=new ImagePanel(player.getCardsOwned().get(i).getImagePath(),cardDim);
card.setName("politicsCard"+i);
card.setBounds(dinstanceX, dinstanceY, cardDim.width, cardDim.height);
dinstanceX+=cardDim.width+space;
politicsCards.add(card);
}
scrollCards.setViewportView(politicsCards);
So, what I've forgotten?