I have this query that kindof works but when I try to remove the frame and just add it to a button on the main GUI it no longer works? Any help appreciated!

Java Code:
   @Action
    public void Query() {

try{
           JFrame frame = new JFrame("Sorting JTable");
           final TableRowSorter<TableModel> sorter =
                   new TableRowSorter<TableModel>(masterTable.getModel());
           masterTable.setRowSorter(sorter);
            masterScrollPane.add(masterTable);
           JButton button = new JButton("Filter");
           button.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               String text = findField.getText();
               if (text.length() == 0) {
                 sorter.setRowFilter(null);
               } else {
                 try {
                   sorter.setRowFilter(
                       RowFilter.regexFilter(text));

                 } catch (PatternSyntaxException pse) {
                   System.err.println("Bad regex pattern");
                 }
               }
             }
           });
           frame.add(button, BorderLayout.SOUTH);
           frame.setSize(100, 100);
           frame.setVisible(true);
        }
         catch (Exception e) {
            System.err.println("Got an exception! ");
            System.err.println(e.getMessage());
        }
    }