• Post Reply Bookmark Topic Watch Topic
  • New Topic

CardLayout .show() method  RSS feed

 
Keith Kiely
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just trying to learn to use the cardlayout feature in windowbulder pro and for some reason or another when the show method will not work for me any help would be greatly appreciated.
Here is what i have so far.



Please take it easy on me I'm new!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what *does* happen?

You should do all the GUI setup in one place (instead of the two methods addComponentToPane and createAndShowGUI that you have now). The passing around of frame_1.getContentPane() is very unusual. Creating a HomeScreen object object doesn't accomplish much, since HomeScreen is not a GUI object that you can display. Instead of creating a separate JFrame in line 110, you could have HomeScreen extend JFrame - then it would make sense to instantiate it, and add objects to its content pane.

(BTW, I edited your post to UseCodeTags for easier readability.)
 
Keith Kiely
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the moment nothing happens when I click the button that changes to the weights tab.
Thanks for the reply I will look at the other stuff you commented on now also.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a logging statement (System.out.println(...)) to the button listener to make sure it is getting executed. As an aside, for a button the usual approach is to use an ActionListener instead of a MouseListener:
 
Keith Kiely
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have changed the button to actionPreformed now and entered the log statement and it is displayed to the console.
The reason I have two methods the methods createAndShowGUI() / addComponentToPane(Container pane) is because I have been following this tutorial should it be different.
http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/layout/CardLayoutDemoProject/src/layout/CardLayoutDemo.java

Also if I use the cardLayout.next(cards);
It works fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!