aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JPanel to JPanel in a JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel to JPanel in a JFrame" Watch "JPanel to JPanel in a JFrame" New topic
Author

JPanel to JPanel in a JFrame

Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
i have a JFrame, inside it i have 2 JPanel.

1st panel will appear in JFrame once i running it.
then i click one button in 1st panel, 2nd panel appear in the JFrame and 1st one will be gone.

the 1st panel appear. but once i click on the button in the 1st panel it cannot go to 2nd panel, but the frame is still there with empty since 1st panel i setVisible(false).

how to make the 1st panel to 2nd panel successfully?

note: i separate the 2 panels and jframe, means i got Panel1 class , Panel2 class , and ABC frame class.


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
from your description, if the panels are added directly to the frame, and
you remove/add the frame's components, you need to call
frame.validate();
after you add the new panel

if you are instead removing/adding from/to a JPanel, you need to call
panel.revalidate();

in both the above, sometimes
repaint();
also needs to be called

another option for you is to create an additional JPanel, and set it as a
CardLayout(). you then add both your other panels to this cardlayout panel
and use the button to switch between panels.
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
thank you.
but i have another question.

i have some textfields in the 1st panel. when i click on a button to save into txt file, the textfields.getText() is not working. and empty space is save into txt file which i DO key in words into textfields.

why that happens?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
for questions like this you should be posting a sample program - just a frame,
textfield, button and actionListener code to save the text to a file.

without a sample program (which shows us how you have put it all together), all you can get is guesses.

guess (1) - duplicate declaration of the textfield



in the above, the 'tf' in the constructor is the one seen on the screen,
but it is not the one referenced in actionPerformed(), and will always save ""

guess (2) - do you close the file after you save the tf.getText()
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
thank you for your reply.
i use the wrong object references.
hehe.
thank you anyway,really.
thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel to JPanel in a JFrame