Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 21st, 2009, 08:32 PM
Registered User
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get a JPanel to make itself dissapear?

Howdy all. (Edit: I swear I know how to spell disappear)

I have a really simple app I'm trying to get going but, I've hit a wall.
I create a simple empty JFrame and display it. When it is displayed a small JPanel pops up asking you to hit one of two buttons:

"Okay" button to change the background color of the JFrame.contentPane to pink.
"Cancel" button to change nothing.

After either button is pressed I want the JPanel with the buttons to go away.

Currently, I have implemented this JPanel as a seperate class - ButtonPanel.

So, my question is: What can I do within this ButtonPanel to make the ButtonPanel go away? When in the ButtonPanel.actionPerformed(Event) method what can I do to make the ButtonPanel go away and possibly change the background color of the contentPane of the JFrame?

I thought about creating some sort of intermediate class to which I would pass an instance of the ButtonPanel. I would also pass an instance of this intermediate class to the ButtonPanel.

The intermediate class would have a method called "makeButtonPanelGoAway()" which could be called in the actionPerformed method of the ButtonPanel to get rid of the ButtonPanel.

However, I figure someone probably thought of a brighter way of handling this. Could anyone tell me a better way of doing what I want to do?

Thanks everyone. Just tell me if none of it makes sense and I'll try to clarify.
Old October 5th, 2009, 02:00 AM
Friend of Wrox
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post

You can use simple option dialog provided in swings [JFC]. Use one of JOptionPane.showConfirmDialog OR JOptionPane.showMessageDialog OR JOptionPane.showOptionDialog

These methods return values referring which button was pressed by the user, you can use this value to decide whether to changes the color or not.

check the java documentation of JOptionPane class at bellow link
- Rakesh
Old July 7th, 2011, 07:02 PM
Registered User
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

hi ...
the first thing JPanle will not appear or disappear cuz it is not like any other componatan the main use of it just as container , you can use visible property to set true or false but the things which visibled or not just which the panel contain....

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing JPanel to Another Class d-mart Java Basics 1 May 29th, 2009 05:50 AM
How to paste a bitmap into a JPanel? AndrewH Java GUI 1 May 1st, 2007 12:19 AM
Can I add a JComboBox twice to the same jpanel david.byrne Java GUI 4 May 14th, 2005 11:42 AM
Some variable dissapear after goin tru 10 pages Monkeycoder Beginning PHP 4 January 5th, 2005 07:46 PM
Dissapear mouse and use key to navigate on web pag karib JSP Basics 0 July 2nd, 2004 12:53 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.