Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 21st, 2009, 09: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.
Reply With Quote
  #2 (permalink)  
Old October 5th, 2009, 03:00 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
http://java.sun.com/j2se/1.5.0/docs/...ptionPane.html
__________________
- Rakesh
http://iam-rakesh.blogspot.com
Reply With Quote
  #3 (permalink)  
Old July 7th, 2011, 08:02 PM
Registered User
 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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....
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing JPanel to Another Class d-mart Java Basics 1 May 29th, 2009 06:50 AM
How to paste a bitmap into a JPanel? AndrewH Java GUI 1 May 1st, 2007 01:19 AM
Can I add a JComboBox twice to the same jpanel david.byrne Java GUI 4 May 14th, 2005 12:42 PM
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 01:53 AM



All times are GMT -4. The time now is 04:45 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.