Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to load a new screen on a JFrame  RSS feed

 
Jacob Steingart
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to Swing/AWT, and I've been fooling around with it lately. I know that you can use repaint() to refresh a JFrame, but that will only re-perform the code that applies to the JFrame, but I want to have a button on the two buttons on the left. When you click the first button, there will be a text field that has something where a user can enter variable(s). When you click the other button, it would take away those text boxes and replace them with something else, say a JTextField or JLabel that would display the variable(s) entered in the previous screen and display them, or display a variable holding the something done to the other variable(s). Basically, I want to be able to "switch" screens by clicking buttons. I know how to put in an ActionListener, etc., but I don't know how to put different widgets on the screen. I also want to know if there is a better way to put things on the screen besides NORTH, SOUTH, WEST, EAST, and CENTER, or if there are ways to put, say, two widgets in the center.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds as if you need to look into trying out the CardLayout. This allows you to swap components held in another component as if they were cards being dealt from a deck. It's pretty slick and the tutorial at the Sun Swing tutorials is pretty good.
 
Preeti Yarla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not a swing expert but I think JTabbedPane might be easier. Again Sun java tutorials shows how to do that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!