Hi,

I'm currently writing an ATM in swing and I used CardLayout to switch between the different panels.
One of the panels is a JTable that supposed to show the client history actions.
I've put the table in a scrollPane but for some reason it doesn't recognize the end of the panel as the end of table, so my scrollPane doesn't show up. I've tried changing either the size of the table or the scroll but it doesn't work.
I've included the code of my main frame and the JTable panel.

Any ideas?


*(ATM FRAME)
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class ATMFrame extends JFrame {
private static final long serialVersionUID = 1L;

public ATMFrame getInstance() {
return this;
}

public ATMFrame() {

this.setTitle("MBank ATM");
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setSize(600, 400);
//this.setResizable(false);
this.setLocationRelativeTo(null);

Color borderColor = new Color(150, 175, 200);
Color backgroundColor = new Color(170, 212, 255);

JPanel center = new JPanel(new CardLayout());

LoginPanel loginPanel = new LoginPanel(center);
loginPanel.setBackground(backgroundColor);
loginPanel.setWrongMassage(false);
center.add(loginPanel, "Login");

this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(Box.createHorizontalStrut(20), BorderLayout.EAST);
this.getContentPane().add(Box.createHorizontalStrut(20), BorderLayout.WEST);
this.getContentPane().add(Box.createVerticalStrut(20), BorderLayout.NORTH);
this.getContentPane().add(Box.createVerticalStrut(20), BorderLayout.SOUTH);

this.getContentPane().add(center, BorderLayout.CENTER);

this.getContentPane().setBackground(borderColor);

}

public void setNextPanel(JPanel panel) {
this.getContentPane().add(panel, BorderLayout.CENTER);
}

public static void main(String[] args) {
ATMFrame atmFrame = new ATMFrame();
atmFrame.setVisible(true);
}
}
#

*(ATM History)
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

import ATM.Controller.ActionListHandler;
import Admin.VO.Display;
import Admin.VO.VOBalanceAction;
import Admin.VO.VOCustomer;

public class DisplayHistoryPanel extends JPanel {

private static final long serialVersionUID = 5L;
private final String FONT = "Arial";
private Color backgroundColor;
private JPanel cards;

public DisplayHistoryPanel(VOCustomer customer, Vector<VOBalanceAction> balanceActionList,
JPanel cards, final Connection conn) {

this.cards = cards;
this.backgroundColor = new Color(170, 212, 255);

JLabel helloLabel = new JLabel("<html><u>" + customer.getName() + " History" + "</u></html>");
helloLabel.setFont(new java.awt.Font(FONT, 3, 20));

String[] tableHeaders = { "Balance ID",
"Customer ID",
"Action",
"Commission",
"Date",
"Comments" };

DefaultTableModel model = new DefaultTableModel(tableHeaders, 0);

int counter = 0;

while (counter < balanceActionList.size()) {
VOBalanceAction action = balanceActionList.get(counter);
Object[] row = { action.getBalance_id(),
action.getCust_id(),
action.getAction(),
Display.NIS(action.getAmount()),
Display.longToShortDate(action.getDate()),
action.getComments() };

model.addRow(row);
counter++;
}

JTable table = new JTable(model) {

private static final long serialVersionUID = 5L;

public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}

//Creates shading for even rows
public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer, Index_row, Index_col);

if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
comp.setBackground(Color.lightGray);
} else {
comp.setBackground(Color.white);
}
return comp;
}

public boolean isCellEditable(int rowIndex, int colIndex) {
return false; //Disallow the editing of any cell
}
};

JScrollPane scroll = new JScrollPane(table);
JButton backButton = new JButton(new ActionListHandler("Back", this.cards));
backButton.setFont(new java.awt.Font(FONT, 1, 15));
backButton.setBackground(new Color(150, 160, 170));

JButton exitButton = new JButton("Exit");
exitButton.setFont(new java.awt.Font(FONT, 1, 15));
exitButton.setBackground(new Color(150, 160, 170));
exitButton.addActionListener(new ActionListener() {

//Closes the ATM if the button "Exit" is clicked
@Override
public void actionPerformed(ActionEvent e) {
try {
conn.close();
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
}
System.exit(0);
}
});

this.setBackground(backgroundColor);
this.setLayout(new BorderLayout());

JPanel northPanel = new JPanel();
northPanel.setBackground(backgroundColor);
northPanel.add(helloLabel);

JPanel centerPanel = new JPanel();
centerPanel.setBackground(backgroundColor);
centerPanel.setBorder(BorderFactory.createRaisedBevelBorder());
centerPanel.add(scroll);

JPanel southPanel = new JPanel();
southPanel.setBackground(backgroundColor);
southPanel.add(backButton);
southPanel.add(Box.createHorizontalStrut(50));
southPanel.add(exitButton);

this.add(northPanel, BorderLayout.NORTH);
this.add(centerPanel, BorderLayout.CENTER);
this.add(southPanel, BorderLayout.SOUTH);
}
}

Thanks for any help,

Alex