File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes CardLayout- how to deal with it? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "CardLayout- how to deal with it? " Watch "CardLayout- how to deal with it? " New topic
Author

CardLayout- how to deal with it?

Stefan Elfvinge
Ranch Hand

Joined: Oct 29, 2001
Posts: 52
Hi! I have a class extending JPanel(ScoreBoard) acting as a scoreboard for a game, ScoreBoard
contains 5 Jpanels, each containing a JTable.
ScoreBoard uses a CardLayout. Adding an instance of ScoreBoard to my JFrame(GameArea) doesn't work.
It compiles, runs, showing all others components(using Flow- or BorederLayout). But ScoreBoard remains invisible!!!??? If I change ScoreBoard's
LayoutManager to something other than CardLayout, it works!!?? What to do...


Steffe
kallam reddy
Greenhorn

Joined: Feb 04, 2002
Posts: 5
hi
you put one empty panel in jFrame(game) and set cardlayout to that, then add Jpanel(scoreboard) to that panel.then it works fine .
Stefan Elfvinge
Ranch Hand

Joined: Oct 29, 2001
Posts: 52
Originally posted by kallam reddy:
hi
you put one empty panel in jFrame(game) and set cardlayout to that, then add Jpanel(scoreboard) to that panel.then it works fine .

Thanks for instant reply!
Do u mean that my mistake is that I first build my
ScoreBoard(JPanel), then add it to the JFrame?
From your advise I take it I should add an additional JPanel, giving it a CardLayout, and THEN, add my ScoreBoard instance to that. Why is this "extra" panel necessary?
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
Stefan, could u post some of the code? to show us the panel and how u add it.
from what i know, i dont think u need the extra panel. the idea should work.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Are you doing the panel.show() for the cardlayout?
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
Paul, i think u dont have to do the show().
if im not mistaken, the card layout will show the FIRST component added to it unless u use next() show() or any of the other functions.
Stefan Elfvinge
Ranch Hand

Joined: Oct 29, 2001
Posts: 52
Thanks for input, here's some code:
private GameController controller
private boolean[] markedValues;
private int summa;
private int bonus;
public ScoreBoard(GameController controller)
{
super(new CardLayout());
setBorder(new EtchedBorder());
this.controller = controller;
markedValues = new boolean[19];
for(int i = 0; i<markedValues.length; i++)
markedValues[i] = false;
}

// To be called from “GameController”
public void addScoreBoardText(DicePlayer player)
{
String name = player.getName();
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(new TitledBorder(new EtchedBorder(),
name + " scoreboard"));
JTable scoreBoardText = new JTable(19, 2);
setupScoreBoardText(scoreBoardText);
panel.setBackground(Color.lightGray);
panel.add(scoreBoardText, BorderLayout.CENTER);
// L�gg texten i panelens container
CardLayout cL = (CardLayout)this.getLayout();
cL.addLayoutComponent(panel, name);
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CardLayout- how to deal with it?
 
Similar Threads
variable that holds a object
constructor problem
how to do automatic refresh
getting a problem ,can't see the button
setting font of JLabel