Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Swapping components  (Read 1705 times)
0 Members and 1 Guest are viewing this topic.
Offline Juriy

Junior Devvie

« Posted 2008-02-07 06:23:56 »

Hi all!

I've got a simple multiplayer black jack game that has several "rooms" and chat. On the UI there's a place for a Component that displays various room info while player is in lobby and a game board while he's playing. I've got separate Components for this tasks. The question is: how to "swap" components in swing correctly?

I've tried calling remove, add and revalidate in sequence and that worked just fine on one of my laptops. On another one I'm having an exception saying that it's impossible to create buffered strategy 'cause component's dimensions are zeros. Unfortunately I don't have the sources to attach right now. Maybe you could suggest some solution just by this symptoms?

Thanks in advance. - java tutorials, tips and tricks (Russian)
Offline fletchergames

Senior Devvie

« Reply #1 - Posted 2008-02-07 16:01:22 »

You need to use either CardLayout or JTabbedPane.  CardLayout essentially swaps several panels in the same spot.  JTabbedPane is basically a CardLayout panel with tabs to switch between the different panels.
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #2 - Posted 2008-02-08 05:17:19 »

Your problem with the buffer strategy is probably due to the window not being created yet. If it hasn't been, getWidth() and getHeight() return zero. After you call setVisible() (and outside of the constructor), try creating your buffer strategy.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Juriy

Junior Devvie

« Reply #3 - Posted 2008-02-08 13:21:10 »

Thanks for your replies!

First of all, I'm using Table Layout (It's not a part of core API, still very usefull). And window has been created already.

I couldn't find out the true reason of this strange behavior but when I changed call sequence to

all worked fine. I've found the solution eventually. - java tutorials, tips and tricks (Russian)
Pages: [1]
  ignore  |  Print  

EgonOlsen (42 views)
2018-06-10 19:43:48

EgonOlsen (22 views)
2018-06-10 19:43:44

EgonOlsen (43 views)
2018-06-10 19:43:20

DesertCoockie (197 views)
2018-05-13 18:23:11

nelsongames (124 views)
2018-04-24 18:15:36

nelsongames (123 views)
2018-04-24 18:14:32

ivj94 (863 views)
2018-03-24 14:47:39

ivj94 (124 views)
2018-03-24 14:46:31

ivj94 (768 views)
2018-03-24 14:43:53

Solater (140 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!