• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

CardLayout- how to deal with it?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you doing the panel.show() for the cardlayout?
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic