0

I have frame, in this frame I have a JTable that have button inside, this button have class with ActionListener and so on and I need to close this frame after pressing this button. How do this?

Code example:

public class Frame2 extends JFrame{   
public  Frame2() {
   JTable table = new JTable(model);
   //...
   table.getColumn("change").setCellEditor(new ButtonCellEditor());
}

public static class ButtonCellEditor extends AbstractCellEditor implements TableCellEditor{
    public ButtonCellEditor() {
        editor = new JButton();
        editor.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              //do something here
              setVisible(false); //not working, I NEED HERE TO CLOSE THIS FRAME
        });
     }}}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
bffn
  • 1
  • 3
  • 1
    1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Apr 24 '16 at 12:03
  • Why does it make sense to have a button in the table that can close the window? – Andrew Thompson Apr 24 '16 at 12:05
  • i am not sure why do you want the specific behavior .. but in order to hide frame you need to call setVisible on frame object – Sanjeev Apr 24 '16 at 12:08
  • this button open other Frame and i need to close this frame when other is openning @AndrewThompson – bffn Apr 24 '16 at 12:09
  • 1
    Bffn, read or re-read @AndrewThompson's link as you obviously are not getting it. – Hovercraft Full Of Eels Apr 24 '16 at 12:10
  • 1
    *"this button open other Frame"* This probably means it should be one frame with a `CardLayout`, or the second frame should be a modal `JDialog` (while the `JFrame` stays open behind it). Read the thread posted in my 1st comment for many ideas. Using 2 or more frames is not a solution here. – Andrew Thompson Apr 24 '16 at 12:11

0 Answers0