0

I need the JInternalFrame that call through a menu / button to always be placed in front of the screen and block the previous ones. I can not do it and I think it is a mistake in the structure of my application. Try in every possible way, I must have some misconception.

Calls, like :

    final Estadisticas frameEstadisticas = new Estadisticas();
    JMenuItem mntmEstadisticas = new JMenuItem("Estadisticas");
    mntmEstadisticas.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (!frameEstadisticas.isVisible()) {
                contentPane.add(frameEstadisticas);
                frameEstadisticas.setVisible(true);
            }
            else {
                JOptionPane.showMessageDialog(contentPane, "Ya tiene esa aplicacion abierta", "Error Aplicacion",JOptionPane.YES_NO_OPTION);
            }
        }
    });

But the result is like this:

1: JInternalFrame "Agregar Alumno"
2: JInternalFrame "Estadisticas"

"Estadisticas" should be in front.

Reference



Sorry for my english.

Arnaud
  • 17,229
  • 3
  • 31
  • 44
German Avalos
  • 53
  • 2
  • 9
  • Where are you calling `toFront()` ? – Arnaud Apr 21 '17 at 13:48
  • @Berger In the block if (!frameEstadisticas.isVisible()) – German Avalos Apr 21 '17 at 13:50
  • The method `toFront()` is NOT used anywhere in the code you posted. If you need more help then post a proper [mcve] that demonstrates the problem. That is all you need is a frame with a desktop pane and two internal frames. Then you add a menu item to bring the frame toFront(). The components on the internal frame are irrelevant to the question. So the entire `MCVE` will be maybe 30-40 lines of code. A small program is easier to debug. – camickr Apr 21 '17 at 14:32
  • @camickr Yes, NOT used. I said "Try in every possible way", in the block If else, I try toFront(), setSelected(), etc... The structure of the program is this: http://imgur.com/a/qfCbn . The calls of the JInternalFrames are externals. I think the problem is in the structure, design error maybe? Ty for reply. – German Avalos Apr 21 '17 at 15:57
  • `I think the problem is in the structure, design error maybe?` - Probably, which is why you need to post your `MCVE`. I suggest you also read the section from the Swing tutorial on [How to Use Internal Frames](http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html) for working examples. – camickr Apr 21 '17 at 17:49
  • @camickr I fixed it, it was a total failure on my part. Without knowing, declare two objects. One in JPanel and another JDesktopPane and add the .add (frame) with the name of the JPanel object... thank you very much for replying, I appreciate it. – German Avalos Apr 21 '17 at 18:16
  • That is why you need to create an `MCVE` to simplify the problem. – camickr Apr 21 '17 at 19:45

0 Answers0