Busted tile algorithm.

The following piece of code from http://www.java2s.com/Code/Java/Swing-JFC/InternalFrameTest.htm does not seem to work as all of the frames are minimized... any one know what gives?

publicvoid tileWindows(){

JInternalFrame[] frames = desktop.getAllFrames();

// count frames that aren't iconized

int frameCount = 0;

for (int i = 0; i < frames.length; i++){

if (!frames[i].isIcon())

frameCount++;

}

int rows = (int) Math.sqrt(frameCount);

int cols = frameCount / rows;

int extra = frameCount % rows;

// number of columns with an extra row

int width = desktop.getWidth() / cols;

int height = desktop.getHeight() / rows;

int r = 0;

int c = 0;

for (int i = 0; i < frames.length; i++){

if (!frames[i].isIcon()){

try{

frames[i].setMaximum(false);

frames[i].reshape(c * width, r * height, width, height);

r++;

if (r == rows){

r = 0;

c++;

if (c == cols - extra){// start adding an extra row

rows++;

height = desktop.getHeight() / rows;

}

}

}catch (PropertyVetoException e){

}

}

}

}

[2451 byte] By [javaroba] at [2007-11-26 12:19:42]
# 1
Maybe this line here:if (!frames[i].isIcon())
zadoka at 2007-7-7 15:08:43 > top of Java-index,Archived Forums,Socket Programming...
# 2
In addition to changing the line I posted you will need to set the state of the frame so that it is no longer minimized:setState()
zadoka at 2007-7-7 15:08:43 > top of Java-index,Archived Forums,Socket Programming...
# 3
In what class will I find setState() ?Thanks.Message was edited by: ccurobert
ccuroberta at 2007-7-7 15:08:43 > top of Java-index,Archived Forums,Socket Programming...
# 4

> In what class will I find setState() ?

>

> Thanks.

>

> Message was edited by:

> ccurobert

Oops. I read to fast. I thought you were dealing with JFrames, now I see it is internal frames.

If you create a example program I am sure someone will take a look at it.

zadoka at 2007-7-7 15:08:43 > top of Java-index,Archived Forums,Socket Programming...
# 5

I'm having the same problem with this similar code that I found, where the windows remain small, ( not minimized ).

Any ideas on how I can get the windows stretched, as tiling normally does?

public static void tile(JDesktopPane desktopPane, int layer)

{

JInternalFrame[] frames = desktopPane.getAllFramesInLayer(layer);

if (frames.length == 0)

{

return;

}

tile(frames, desktopPane.getBounds());

}

public static void tile(JDesktopPane desktopPane)

{

JInternalFrame[] frames = desktopPane.getAllFrames();

if (frames.length == 0)

{

return;

}

tile(frames, desktopPane.getBounds());

}

private static void tile(JInternalFrame[] frames, Rectangle dBounds)

{

int cols = (int) Math.sqrt(frames.length);

int rows = (int) (Math.ceil(((double) frames.length) / cols));

int lastRow = frames.length - cols * (rows - 1);

int width, height;

if (lastRow == 0)

{

rows--;

height = dBounds.height / rows;

} else

{

height = dBounds.height / rows;

if (lastRow < cols)

{

rows--;

width = dBounds.width / lastRow;

for (int i = 0; i < lastRow; i++)

{

frames[cols * rows + i].setBounds(i * width, rows * height,

width, height);

}

}

}

width = dBounds.width / cols;

for (int j = 0; j < rows; j++)

{

for (int i = 0; i < cols; i++)

{

frames[i + j * cols].setBounds(i * width, j * height,

width, height);

}

}

}

javaroba at 2007-7-7 15:08:43 > top of Java-index,Archived Forums,Socket Programming...
# 6
Looks like it plays off of 'ALL' frames, visible or invisible.. how do I filter for just visible frames?
javaroba at 2007-7-7 15:08:43 > top of Java-index,Archived Forums,Socket Programming...