Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I preferred to create in my Main Frame class (which extends JFrame) the following function:</p> <pre><code>private void showIntFrame(Class intFrameClass) { JInternalFrame targetFrame = null; int xoff = 0, yoff = 0; for(JInternalFrame jif : jdp.getAllFrames()) { if(jif.getClass().equals(intFrameClass)) targetFrame = jif; if(jif.getLocation().x &gt; xoff) xoff = jif.getLocation().x; if(jif.getLocation().y &gt; yoff) yoff = jif.getLocation().y; } if(targetFrame == null) { try { Constructor&lt;JInternalFrame&gt; c = intFrameClass.getConstructor(MainFrame.class); targetFrame = c.newInstance(MainFrame.this); } catch (Exception ex) { System.err.println("Exception in MainFrame.showIntFrame() while creating new JInternalFrame instance. " + ex.getLocalizedMessage()); ex.printStackTrace(); return; } jdp.add(targetFrame); targetFrame.setLocation(xoff + 30, yoff + 30); } targetFrame.setVisible(true); try { targetFrame.setSelected(true); } catch (PropertyVetoException ex) { System.err.println("PropertyVetoException in MainFrame.showIntFrame() while activating JInternalFrame instance. " + ex.getLocalizedMessage()); } } </code></pre> <p>Here jdp is instance of JDesktopPane, which previously was set as ContentPane of my main JFrame.</p> <p>Because my programs often contain numbers of different classes, inherited from JInternalFrame, it is easier to call this function from event handlers to show new subclass of JInternalFrame.</p> <p>Every subclass of JInternalFrame in my programs have one constructor with one parameter - MainFrame (main JFrame).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload