Having Trouble Closing a JFrame With a Button Click in Swing
I am brand new to Java so this is probably something really stupid.
On my main form I have a table displaying records from a database. When you double click a record, it pops up a second form showing the details of that record. You can then edit the data in this second form and click a "save" button which saves the data to the database. I want this button to also close that second form, however in the button click event, the second form variable is null.
Here is some code showing the basic concept:
public class SampleForm {
private JButton saveJobButton;
private JFrame frame;
private JFrame editDetailFrame;
public static void main(String[] args) {
SampleForm sample = new SampleForm();
sample.createMainFrame();
public void createMainFrame() {
frame = new JFrame();
JComponent panel = buildPanel();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
public void createEditFrame() {
editDetailFrame = new JFrame();
editDetailFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JComponent editPanel = new SampleForm().buildDetailPanel();
editDetailFrame.getContentPane().add(editPanel);
editDetailFrame.pack();
editDetailFrame.setVisible(true);
editDetailFrame.validate();
// save button
private JButton getSaveJobButton() {
if (saveJobButton == null) {
saveJobButton = new JButton();
saveJobButton.setText("Save Job");
saveJobButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
.. saves data to database.
// here is where I thought the dispose() should go but the editDetailFrame is null at this point.
editDetailFrame.dispose();
return saveJobButton;
}Any assistance would be much appreciated.
That handles the NullPointer, but still doesn't close my second Frame. The editDetailFrame should not be null at this point as I am clicking a button on the editDetailFram itself so I think the problem is that I just don't have a reference to the actual object at that point and my variable is just an empty one.
Similar Messages
-
Having trouble opening a pdf with Adobe...keep seeing an error sign "acroExch" does anyone have a way to fix this?
Hmm, "Use Adobe Reader" should launch the PDF outside of Firefox in the stand-alone Adobe Reader application, so seeing it in a tab is something of a puzzle.
Could you check your version of Adobe Reader? For Windows 7, you normally would have the Reader XI series (Reader 11), which has had several updates. From inside Adobe Reader, you can use Help > Check for Updates to make sure it's current.
In Firefox, could you check your Adobe Acrobat plugin version or possibly versions? You can view that on the Add-ons page. Either:
* Ctrl+Shift+a
* "3-bar" menu button (or Tools menu) > Add-ons
In the left column, click Plugins. If you find multiple versions, this can cause problems and may need to be cleaned up manually (post back on that for suggestions).
Sometimes, the settings file which stores those download handler preferences becomes corrupted and there's not much else to do than to rename or remove that file and let Firefox rebuild it.
To do that, open your current Firefox settings (AKA Firefox profile) folder using either
* "3-bar" menu button > "?" button > Troubleshooting Information
* (menu bar) Help > Troubleshooting Information
* type or paste about:support in the address bar and press Enter
In the first table on the page, click the "Show Folder" button. This will launch a new window (Windows Explorer window) listing various settings files.
Leaving that window open, switch back to Firefox and Exit, either:
* "3-bar" menu button > "power" button
* (menu bar) File > Exit
Pause while Firefox finishes its cleanup, then rename '''mimeTypes.rdf''' to something like mimeTypes.old
Start Firefox back up again and "PDF Files" should be back to their default setting of "Preview in Firefox". Try changing that to "Use Adobe Acrobat (in Firefox)" and test to see whether there's any improvement. -
Having trouble sharing my folio with a client
I'm having trouble sharing my folios with clients. I clicked the share button and sent the e-mail to the client. They received the e-mail and signed up for an adobe account. When they try to log into Adobe Content Viewer on their iPad using their Adobe credentials they keep getting log in failed notices. Does anyone know why this is happening? Thanks.
After they log in and accept the terms they should be able to log into the ACV with that account and download the folio.
-
is anyone else having trouble setting up messages with the new mountain lion software? I keep getting a notification that i cant sign in and it is saying, check network connection and try again, but i have full wifi bars, thanks, Justin
Install this to get X11 functionality back in 10.8
http://xquartz.macosforge.org/landing/
Worked great for me and others.
Jerry -
me and my wife are having trouble udating our iphones with itunes our passwords havent changed. when i try to udate my iphone her email address comes up and wants her password and when she udates her iphone apps my email address comes up and sometimes it says the passwords are incorrect. is the problem that i used my credit card . we dont buy apps we just get the free ones. she tried one time to use her credit card and it would not take the card no. can u help me with this problem. just to let you know i did the other day change my password thought that might help but it didnt
Read here > How to use multiple iPods, iPads, or iPhones with one computer
-
I am having trouble viewing PDF's with Adobe Reader XI
I am having trouble viewing PDF's with Adobe Reader XI
I am using Windows 7 home edition and using Internet Explorer 10
The PDF's are online on websites that I am trying to open. Both on the site as well as trying in a new window.
Thank you
Jeff -
I am having trouble pairing my iPhone4 with bluetooth device. It was connected but is not able to connect after both devices were shut and then switched on, as per Apple instructions. phone does find any bluetooth device closeby. how to fix?
NovaRiddle wrote:
I am having trouble pairing my iPhone4 with bluetooth device. ...
Depends on the device...
Have a look here for Supported Bluetooth Profiles
http://support.apple.com/kb/HT3647 -
I am having trouble installing lightroom 5 with this error message:
Payload: AdobeLightroom5CCMPkg-mul 5.2.0.0 {4b06fc24-6249-4c57-9830-6008a3ce9a80} -----------
ERROR: DW006: Apple Package failed to install successfully.
ERROR: Third party payload installer Adobe Photoshop Lightroom 5.pkg failed with exit code: 1
what should I do? BillmebHi BillMeb,
Please refer the knowledge base article: http://helpx.adobe.com/lightroom/kb/exit-code-7-displays-installing.html.
Regards,
Romit Sinha -
im having trouble activating my CS2 with my original serial number as well as the new serial number privided by Adobe
You must download and install the CS2 version provided by Adobe and you must use the new serial number provided by Adobe.
https://www.adobe.com/cfusion/entitlement/index.cfm?e=cs2_downloads -
I am having trouble connecting to internet with my iphone 5, Are there any issues with with iphone 5 that would cause this problem?
Perhaps something in Apple's support article on troubleshooting problems with WiFi connections will help:
http://support.apple.com/kb/TS1398
Regards. -
Hello guys. I'm having trouble opening Instagram pages with Safari.
Hello guys. I'm having trouble opening Instagram pages with Safari. I try to open them and it seems to be loading for one second, but then it's all blank, there's nothing on the screen. Funny thing is, when I try to open an Instagram page that doesn't exist, it opens the Instagram NOT FOUND page. I don't know what's going on. I've tried everything, from software updates to restarting my Mac etc. Please help.
Is this the site you are referring to > http://instagram.com
Because that site refers you to apps for smartphone devices. Not for your Mac.
Regardless of the Instagram website, v10.5.4 is an outdated version of Safari. You need to update your system software.
Click your Apple menu top left in your screen. From the drop down menu click Software Update.
Restart your Mac after the updates are installed, then try Instagram on Safari. -
I am having trouble making TM work with my new iMac.
I'm having trouble making TM work with my new iMac. I have an external drive, Freeagent GoFlex Drive, that is recognized on the desktop and in the drive utility. Time machine just "spins it's wheels" and doesn't seem to transfer any information. I have run repair disk on both drives and repair permissions. Any ideas how I can make this thing work?
Did you format the HD first. It has to be formatted to Mac OS Extended (Journaled). If you're not sure how to do this please read:
http://www.cultofmac.com/92845/formatting-external-hard-drives-in-os-x-video-how -to/ -
I am having trouble syncing my iPhone5 with my PC computer. It is only syncing and transferring 50 contacts were as I have over 350 contacts. I have followed the step by step procedure with no luck. Does anyone have any ideas how to resolve otherwise I will have manually load each number individually please help.
Any errors?
What application are the contacts stored in? -
Having trouble syncing my iphone with my computer. Some of the playlists will sync while other playlist folders will not sync.
An important info is missing, what computer are you using?
iTunes Sidebar can be activated in
Computer iTunes menu > View > Show Sidebar.
iOS: Device not recognised in iTunes
Windows: http://support.apple.com/kb/TS1538
Mac: http://support.apple.com/kb/TS1591 -
Having trouble installing windows 7 with Parallels
I am having trouble installing windows 7 with Parallels, i keep getting the following message: There is no operating system installed in this virtual machine. Please insert an operating system installation CD into the optical drive of your Mac and restart. Any thoughts?
I would post in the Parallels forums.
Maybe you are looking for
-
When I tried to open the web browser the browser flashed black and white at start up, then all the applications when i open a new window are completely black, I am unable to view the drop down menus as the come out as random pixels. This happens to a
-
I made a duplicate of an imovie HD project so I could have two different versions. I tried making the copies both by using File> Duplicate and the Save As command in imovie. When I changed the title on the copy, the video stuttered when I played it
-
Macbook Pro power supply and grounding.
Hey Apple people. I noticed something disconcerting with the power supply on my MacBook Pro 13" (non-retina) I have a stainless steel metal table in my kitchen. It is the same type of stainless steel table you find in restaurants. I have my 13" MacBo
-
Hi, I have made the RRI setting from Opportunity Monitor report to opportunity display screen but I am getting the below error. No Web server maintained for the presentation of log. system BCD363" ITS is there in BW. Kindlylet me know how to get thi
-
Observer pattern in BC4J?
Just wondering if anyone has implemented a publisher/subscriber (or observer) pattern with BC4J? For instance, has anyone implemented an application module supporting multiple clients that allows clients to call a method to send a message to all the