0

I'm with some trouble here

I did a main CRUD form, and one button at this form that when clicked it calls another form, this one responsible for makes a query at the database to order the dates and hours that were entered by the user and display at the screen... but here is the deal, when I click at the button "Listar Por Prioridade" to call this form "Trabalhos Prontos" it appears behind the first one "Registro de Novos Chamados"... I've tried to use:

private void btListarPrioridadeActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        try {                                              
            man = new MySQLDaoManager("root", "", "localhost", "atendimentos", 3306);
            try {
                FormTrabProntos frmTrbPrnt = new FormTrabProntos(man);
                frmTrbPrnt.setVisible(true);
                frmTrbPrnt.toFront();
                FormNovaChamada frmNvCham = new FormNovaChamada(frmini, editavel);
                frmNvCham.toBack();

            } catch (DAOException ex) {
                Logger.getLogger(FormGestor.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (SQLException ex) {
            Logger.getLogger(FormGestor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

and nothing (see image below).. anyone knows how could I fix this problem and make the called screen appears at the front of the first one?! Thanks a lot![enter image description here

Frakcool
  • 10,915
  • 9
  • 50
  • 89
theEarlyRiser
  • 134
  • 12
  • This may help you: [http://stackoverflow.com/questions/309023/how-to-bring-a-window-to-the-front](http://stackoverflow.com/questions/309023/how-to-bring-a-window-to-the-front) – byxor Dec 01 '16 at 19:20
  • 1
    The default behaviour is to show a frame at the front when `setVisible(true)` is used. Change the order of your logic to make the frame you want on the front the last one that is made visible. – camickr Dec 01 '16 at 19:21
  • Easiest of all would be to show only 1 screen at a time. What use is it so show a JFrame that is stuck behind another in the background? Just set the parent visibility to false when showing the prompt JFrame and set the visisbility back to true when you close the prompt JFrame – Filip Dec 01 '16 at 19:30
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Dec 02 '16 at 03:39
  • Thanks a lot for everyone that helped here!!! I did it today and it finally worked!!! i've noticed that isn't works if i call another JFrame with another one together and with that it occurs that conflict... i've fixed setVisible(false) and disposing the firstOne and so setVisible(true) and toFront() on the other one – theEarlyRiser Dec 03 '16 at 16:36

1 Answers1

-1

Finally i've solved it, the function stayed as follows:

private void btPriorityListActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        try {                                              
            man = new MySQLDaoManager("root", "", "localhost", "attendances", 3306);
            try {
                setVisible(false);
                dispose();
                FormTrabProntos frmTrbPrnt = new FormTrabProntos(man);
                frmTrbPrnt.setVisible(true);
                frmTrbPrnt.toFront();
                frmTrbPrnt.requestFocus();
             
            } catch (DAOException ex) {
                Logger.getLogger(FormGestor.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(FormGestor.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 

Big thanks for the help!!!

theEarlyRiser
  • 134
  • 12
  • Your REAL problem is that you are using `JFrame` for cases where you should be using `JInternalFrame`. As Andrew Thompson suggested, study his recommended post on the use of multiple `JFrame`. You posted "one button at this form that when clicked it calls another form". Most likely, the "form" with the button would be a `JFrame`. All other "forms" called from within this frame, should be `JInternalFrame` objects. Do this, and you would not have to dispose of the parent frame. – hfontanez Dec 03 '16 at 16:47
  • Hi hfontanez! Thanks a lot for the tip, i'm gonna do it now, i was doing this code a little hurry because my final paper presentation this Monday and i was a little desperated, so, on that register screen i keep it as a JFrame and in this second one a JInternalFrame isn't it? – theEarlyRiser Dec 03 '16 at 17:46
  • yes. Your main (program) window should be a `JFrame` and all other dependent windows should be 'JInternalFrame`. Here's a good tutorial: https://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html – hfontanez Dec 04 '16 at 20:40