[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Close button

How do i make a close button that will close a jframe window
0
jedistar
Asked:
jedistar
  • 3
  • 2
  • 2
  • +1
3 Solutions
 
hoomanvCommented:
add actionlistener to do

{
   frame.setVisible(false);
   frame.dispose();
}
0
 
CEHJCommented:
Add it to the form and in the action listener


button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
            dispose();
      }
});
0
 
objectsCommented:
JButton button = new JButton("Close");
button.addActionListener(new ActionListener()
{
   public void actionPerformed(ActionEvent event)
   {
       JButton source = (JButton) event.getSource();

       // assuming the button is in the frame you want to close

       SwingUtilities.windowForComponent(source).dispose();

      // or if you know which frame yopu want to close and have a reference to it

      frame.dispose();
   }
});
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jedistarAuthor Commented:
whats this?
0
 
jedistarAuthor Commented:
SwingUtilities.windowForComponent(source).dispose();
0
 
hoomanvCommented:
Returns the first Window ancestor of the given component, or null if source is not contained inside a Window
0
 
hoomanvCommented:
that was the description of windowForComponent(Component c) method
0
 
CEHJCommented:
:-)

>>frame.setVisible(false);

would of course be redundant in that context
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now