Hi,
I am trying to implement the show method, of cardlayout. However i cannot get it to work.
Whether i use JP[5][1].getName()Code:public class Main {
JFrame guiFrame;
CardLayout cards;
JPanel cardPanel;
public static void main(String[] args) {
// Use the event dispatch thread for Swing components
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
new Main();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public Main() throws IOException {
guiFrame = new JFrame();
guiFrame.setSize(800, 600);
cards = new CardLayout();
cardPanel = new JPanel();
cardPanel.setLayout(cards);
final JPanel[][] JP = new JPanel[27][2];
for (int i = 0; i < JP.length; i++) {
JP[i][1] = new JPanel();
JP[i][1].setBackground(Color.white);
cardPanel.add(JP[i][1]);
}
JButton [][] Category = new JButton[5][2];
for (int i = 0; i < Category.length; i++) {
JButton bRec = new JButton();
Category[i][1] = bRec;
JP[1][1].add(bRec);
bRec.setFont(FirstFont);
bRec.setBorder(BorderFactory.createLineBorder(Color.black));
bRec.setBackground(BackGround);
bRec.setForeground(Color.white);
ButQuestions500[0][1].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
cards.show(cardPanel, "JP5");
}
});
guiFrame.add(cardPanel, BorderLayout.CENTER);// add to frame in center
guiFrame.add(backTab, BorderLayout.SOUTH);
guiFrame.setVisible(true);
}// Showing only problematic area
or the current method it will not flip to that card.
Thanks

