-1

I am using Java Swing. I am adding internal frames with the help of menus in layered pane.

Whenever a new layer (another new internal frame) is added in it, it goes to the back of all frames. Can you please tell me how to bring the newly added jInternalFrame to top of all exsisting internal frames on a jLayredPane.

Thanks!

kleopatra
  • 51,061
  • 28
  • 99
  • 211
DJ'
  • 1,760
  • 1
  • 13
  • 26
  • 1
    Does [`moveToFront()`](http://docs.oracle.com/javase/7/docs/api/javax/swing/JLayeredPane.html#moveToFront%28java.awt.Component%29) not achieve the stated effect? – Andrew Thompson Mar 12 '12 at 13:31
  • how exactly do you add the new layer/internalFrame? – kleopatra Mar 12 '12 at 14:52
  • Why a question asked in 2012 will get a vote down in 2014 even when it was answered and accepted long ago :s – DJ' Sep 15 '14 at 10:25

2 Answers2

1

How's this?

myLayeredPane.moveToFront(newlyAddedInternalFrame);
c24w
  • 7,421
  • 7
  • 39
  • 47
0

Thanks c24w for the answer, it is correct.

I managed to get another thing to work this around:

try { ab.setSelected(true); } catch (Exception ex) { System.err.append(ex.toString()); };
DJ'
  • 1,760
  • 1
  • 13
  • 26
  • Presumably, where `ab` is the jInternalFrame to bring forward? You can achieve the same effect with `ab.toFront()`, as Adam mentioned previously. – c24w Mar 13 '12 at 16:49