4

Is there any default functionality for arranging JInternalFrames in Java Swing?

I would like to have the Cascade, Tile, etc... functionality within my Java Swing application like this: http://www.codeproject.com/KB/cs/mdiformstutorial.aspx I could only find code where they did the arranging manually. Is there no support for this in Java Swing or am I a bit blind?

juFo
  • 17,849
  • 10
  • 105
  • 142

2 Answers2

6

I've done cascade before but I did it by shifting the frames pixels to create the affect I do not know another way of doing this, I would work out how big the JDesktopPane is then get an array of you internal frames with getAllFrames(), then perform the sizing and shifting manually.

I am certain (allthough I haven't looked for at least 2 years now) that swing has no other way to perform these operations, I'm sure someone somewhere has a written a third party library to bolt onto swing apps, if not I'd write one and open source it :)

Edit,

Just thought the other way you could do tile etc, would be to write a custom layout manager that did the heavy lifting work for you something like FrameTileLayoutManager, then use that.. its just a thought.

krystan honour
  • 6,523
  • 3
  • 36
  • 63
0

This is not really a solution but more of a Hack. It is possible to cascade/ stack the internal frames if you can read the current width of the desktop pane before rendering the frame.

    int c=desktopPane.getAllFrames().length;
    Random r=new Random();
    if (c<3){
            RegistryDash registry = new RegistryDash();
            registry.setVisible(true);

            desktopPane.add(registry);
            //registry.setLocation(r.nextInt(200),r.nextInt(200));
            registry.setLocation(c*50,c*50);
            try {
                registry.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {
            }

    }else{
     JOptionPane.showMessageDialog(this,"More than three similar windows are currently active. Close some to allow new windows.","Multiple Window Error",JOptionPane.WARNING_MESSAGE);  
    }
  • the question is 10 years old. I'm sure there are far better solutions to this now. (Try .net core ;-) ) – juFo Apr 28 '20 at 07:19
  • 1
    Unfortunately, I encountered the same problem and didnt have a better solution had to come up with the code above. Lastly Java hasnt changed much. :P – Shadrack Kimutai Apr 28 '20 at 19:22