Close JFrame by press JButton
i wonder how to close JFrame...
i know that DeafultCloseOperation... to this for me by pressing X...
but how can i close the JFrame by pressing JButton...
what do i have to do?
to create new Event to do this or what?
thx
cya
You can just call dispose();
btnClose.addActionListener(
new ActionListener()
// pass query to tthe frame
public void actionPerformed( ActionEvent event )
dispose();
} // end actionPerformed
} // end ActionListener inner class
); // end call to addActionListener
Similar Messages
-
hi all,
i have a JFrame. on that frame i put a JTabbedPane. on this pane i add a JPanel. and on this panel there is a JButton "exit". when this button is clicked, a JDialog opens that asks the user if he really wants to quit. when the user clicks "yes", i would like the frame to close, without using the System.exit() command (since the frame is opened from another JFrame, and that one isn't supposed to shut down).
does any of you know how to do that? thanks a lot people!thanks woodi,
i know that i could use these methods, but the problem is i cannot tell the program which frame to close; since i'm using:
JFrame --> JTabbedPane --> JPanel --> JButton --> JDialog
how to tell the JDialog that i want to distroy the JFrame? -
I opened a pdf file that was attached to an email message I received and now it will not close when I press "Done" as files usually do. Does anyone have a solution to suggest please? Thanks.
Try double clicking your home button then force close the stuck PDF by swiping upward. Once you've done that just click the home button again to exit.
-
the "not enough storage" window wont close when i press close and it wont reset because my lock button is broken. what do i do?
Battery does not appear to charge
Important: iPod touch cannot be charged with a FireWire-based power source.
Verify that the power source being used is working properly.
If connecting to a computer's USB port, verify it is a high-powered USB 2.0 port. Note: The USB ports on most keyboards don't provide enough power, so if you're connecting iPod touch to a keyboard, make sure it has a high-powered USB 2.0 port.
Verify the computer is turned on and not in sleep or standby mode. If iPod touch is connected to a computer that's not turned on or is in sleep or standby mode, the iPod touch battery may drain.
Try another USB port.
Try charging from a USB charger if available.
If that does not help, try another USB cable if available.
Learn more about charging the battery.
The Home button isn't working
Put the iPod Touch to sleep.
Wait a couple of seconds.
Press the Home button.
iPod Touch should wake up.
If iPod Touch does not wake up, then iPod Touch should be serviced.
Resources for Service
http://support.apple.com/kb/he57
https://selfsolve.apple.com -
How to perform action when the close button is pressed?
i am using a JInternalFrame and i would like to perform some actions before the internal frame closes when i press the close button on the top right corner of the frame.
i know the first step is:
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
what next? what actionlistener shd i use??
thx very muchYour first step is wrong.
yourInternalFrame.addInternalFrameListener(
new InternalFrameAdapter(){
public void internalFrameClosing(InternalFrameEvent e){
// do part
}); -
To close JFrame over a JDialog
Hi,
I am facing a slight problem. Say I have a code like under
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class abc extends JDialog implements ActionListener
JPanel jp1 = new JPanel();
JButton ok1 = new JButton("OK");
public abc()
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(jp1,BorderLayout.CENTER);
jp1.add(ok1);
ok1.addActionListener(this);
ok1.setActionCommand("ok1");
public void actionPerformed(ActionEvent e)
if (e.getActionCommand().equals("ok"))
System.out.println("Inside action performed method");
else if (e.getActionCommand().equals("ok1"))
JFrame j1 = new JFrame();
JPanel jp2 = new JPanel();
JButton btn1 = new JButton("OK");
j1.getContentPane().add(jp2);
jp2.add(btn1);
btn1.addActionListener(this);
btn1.setActionCommand("ok");
j1.show();
j1.pack();
j1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public static void main(String args[])
abc ABC = new abc();
ABC.show();
ABC.pack();
Now here in this code the line
j1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
closes the application itself. What I want is only the JFrame closes while the main Dialog stills stays in context.
Can someone help with me how I can achieve the same.
Regards.
AnandThere is a dialog it has a OK button. When I click the OK button a frame opens with another OK1 button in it.
Now if I click the "x" sign of the frame it should be disposed without doing anything. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)But if I click the OK1 button then also the frame should be disposed but
after doing something other processing corresponding to the OK1 button.
OK1.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do processing
frame.setVisible(false);
// add this if you want to remove the frame from memory and recreate it when it needs to be opened
frame.dispose();
})>
And within all this the parent(JDialog) and the child(JFrame) should be modal.A JFrame unfortunately cannot be modal, so you shd use a JDialog instead.
ICE -
JFrame, button press opening new window
Hi im working with JFrame right now.... but what i want, is when i press a button that it will open a new window. With new text, images. Like a new class :P. Can someone help me get the code for it . I dont know it :S
Thx
Regards
Patrickthere's no magic going on here.
See
JButton
ActionListener
You should already know how to create and visualize a JFrame -
Itunes closes whenever i press a key
Itunes 8.2 works fine, except... whenever i press a key on my keyboard anywhere, not just while in a text box, the entire program just closes. and yes. i tried uninstalling and reinstalling and repairing the file. i don't know what to do. it's so frustrating pressing any key while itunes is open automatically closes it. i even tried toggling the one key navigation.
No, I've never heard of that!
Try these MSCONFIG directions and see if it still happens.
http://support.apple.com/kb/HT1275 -
Question on not to close JFrame when close button is clicked
Hi All,
Good Morning
I have frame created like:
JFrame frame=new JFrame();When we give
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);The above statement closes the frame but i want the same frame to be hidden in the statusbar.So can any one help me in providing any built in method if there or else how to do it??
Thanks in advance.
regards,
Viswanadhbut i want the same frame to be hidden in the statusbar.Thats what the "minimize" button is for. Don't mix the functionality of the two buttons.
-
Hello,
I have a java application in NetBeans. I have been using Netbean absolut layout. I didn´t create JFrame class variable at all, instead using:Ok is a button
ok.setFont(new java.awt.Font("Arial", 0, 10));
ok.setToolTipText("ok");
ok.setLabel("ok");
ok.setMargin(new java.awt.Insets(2, 2, 2, 2));
getContentPane().add(ok, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 150, 60, 20));
ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okPerformed(evt);
I don´t want to use System.exit(0); because it will shut down whole system. In order to use dispose method, I created a JFrame class variable in beginning of the class, but it doesn´t work.
JFrame frame = new JFrame();
public void okPerformed (java.awt.event.ActionEvent evt){
this.frame.dispose();
Can anyone help me?
Thankshello,
Thanks for replying my message so fast.
I tried, but it still doesn´t work. I am using netbeans absolute Layout. It doesn´t really have frame. Here is my code
public class tt extends JFrame{
JFrame frame = new JFrame();
JTextField text1= new JTextField(20);
JButton ok = new JButton();
public tt throws Exception
setSize(400,300);
setTitle("tt");
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
text1.setFont(new java.awt.Font("Arial",0,12));
text1.setBounds(5, 8, 5, 5);
text1.setEditable(true);
getContentPane().add(text1, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 30, 100, 20));
ok.setFont(new java.awt.Font("Arial", 0, 10));
ok.setToolTipText("ok");
ok.setLabel("ok");
ok.setMargin(new java.awt.Insets(2, 2, 2, 2));
getContentPane().add(ok, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 150, 60, 20));
ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okPerformed(evt);
setVisible(true);
public void okPerformed (java.awt.event.ActionEvent evt){
setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
Thanks -
Adobe Reader X closes when I press any key in the keyboard.
Hello,
I have recently updated my windows from xp to 7 and installed the latest version of adobe reader. Then I encountered a problem, after some time using my PC, Adobe Reader would close whenever I touched any key in my keyboard, but not on my mouse, so I could only view pdf files by moving around using the mouse, and loss funcionalities like searching for a word in the document, or saving it with a different name. The only way to solve this problem was to restart my PC, and then everything would be allright for a while, then the problem happened again. I uninstalled and installed Adobe again, however this problem persists, so I'm seeking help here.
There is another thread with the same problem here http://forums.adobe.com/thread/901383, however it's dead and no solution is presented.
Any help would be great, regards from Chle.I answer myself, solution is here http://forums.adobe.com/message/3806894#3806894, it took me a while to find it though.
-
Resizing JFrame with a Jbutton click
I've witten a simple GUI program that if you click on one button it increases the size of the JFrame and the other button will decrease it. The problem is I tried using ComponentResize() putting a listener on the buttons,but it wouldn't work. Anybody with an idea of how I could do this?
try this code
public void actionListener (ActionEvent e)
int increment = 20;
frame.setBounds (0,0,frame.getWidth()+increment,frame.getWidth()+increment);
} -
Reader X closes automatically when pressing any key
Hi everyone, I updated the Reader yesterday and now the following occurs:
I may adjust the toolbars, make snapshots, print, etc. - but whenever I am hitting the keyboard, either when trying to enter a comment or when choosing side numbers in the printer menu, the program closes automatically without further comment, error message, etc. It may be opened again without any problems, but I cannot find a solution to the keyboard problem. I am using Windows XP, SP 3.
Thanks in advance for your help!I was having this issue today on a co-worker's machine.
However I found a solution thanks to brian.hart.
Go into your registry editor (Run >> regedit)
Go to Hive [HKEY_LOCAL_MACHINE\Software\Policies\Adobe\Acrobat reader\10.0\FeatureLockDown]
Right click >> go to New >> DWORD
Give it the name "bProtectedMode"
Hit okay. Close Regedit. Win.
You may have to restart the computer. I didn't have to though. -
Imovie closes when i press cmd-k
have been using imovie hd 6 to edit a film for about 2 months now, but all of a sudden last night the program started to close down unexpectedly every time i tried to crop a clip. this is getting extremely annoying and i am at a bit of a loose end, especially considering all the problems i have had editing this film in the past, so any help is invaluable. thanks.
Hello, livvy123,
Welcome to the discussions.
Whenever an application begins to do weird things, suspect a corrupted preference file. You should delete this file. iMovie will create a new fresh one automatically when you reopen it.
Close iMovie, go to your Home folder: (YourUserName)/Library/Preferences/com.apple.imovie.plist
Drag this plist file to the trash.
Reopen iMovie and see if it is working properly now.
Post back if this doesn't help. -
IPhoto closes when I press the red X.......
When using iPhoto, if I click the red X it actually closes. The little indicator dot under the icon in my dock goes away. I thought you have to click "command + Q" to close programs? What gives? All of my other programs stay open if I hit the red X. Is this something that got screwed up with 10.5.5 or ????
Thanks,
SteveiPhoto only uses one window in normal usage, and if you close that window, it assumes you want to quit the whole program. Some other applications, such as System Preferences, work the same way.
(37699)
Maybe you are looking for
-
Does not show my hard drive when i try to install Tiger...
I have a Powerbook G4 that has no operating system installed yet, so when i try to install Tiger, i have to put the DVD in while booting up. I went to the installing screen, and i agreed to everything and all, but when i got to the part where it asks
-
[AS][IDCS3] PDF Export Preferences Color Conversion setting
I want to set the field of Color Conversion (as equivalent to manual setting under Output>Color>Color Conversion) to "No Color Conversion" in Applescript but couldn't figure it out. My skeleton Applescript is as follow:- tell application "Adobe InDes
-
MacBook Pro 13" 5.5 (mid 2009) new hard drive not detected
Hi, New here, tried searching for the answer here but could not find any. I got a few hard drive error on my old macbook black 250gb drive that I put in this MacBook pro. The system became really slow and kept hanging (beachball). So I went out and b
-
I have noticed over the past week that after taking a picture with my iPhone 4S (OS7.0.4) the picture is in the camera roll but when I try to view it's blank. I can take multiple pictures but 90% will all end up blank.
-
Assign value to the DFF fields in the OA Page
Hi, I have a requirement to copy customer address defined at the customer level to the contact while creating customer contact in Sales User. The page has the address fields like - Address1, Address2, county, state etc. when I open the page in JDev,