A powerful Java grid layout manager

xiaoxiao2021-03-06  117

MutableGridLayout is a powerful Java interface grid layout.

The basic layout is the N row M column, the line spacing, and the column spacing are XGAP, YGAP, can be constructed for construction method New MutableGridLayout (int COLs, int Rows, int XGAP, int XGAP).

The width (height) of each row (height) can be set by SETWIDTH (INT NUM, DOUBLE VALUE), if the value is greater than 1 It is considered an absolute width if it is considered less than 1, and the layout manager will set the width (height) of each row according to this.

When a basic layout is completed, you can get the corresponding grid through GetBox (int COL, int ROW).

After getting the grid, you can use Split (int Row, Int COL) or SPLIT (int Row, int COL) or split (int yGAP), you can also use MERGE (int Startx, int Starty, int endx, int Endy puts multiple cells.

After the basic layout passes through various sections and mergers, as long as the Container's Layout is set to the layout, the layout will be placed in the order of the top to bottom according to the sequential order of the control, and the top to bottom.

Each composite fill method can be set to expand into a full-specific or component optimal size by setfill. The horizontal alignment between the components and mesh has left / center / right, and vertical alignment is top / middle / bottom. And the grid can be set to empty setblank (TRUE), that is, the component does not put it in the grid.

The following is a source code called, which can be used as a reference:

* This is a Java layout class. * This class divides a container into the X row, Y column, the spacing is XGAP, YGAP, each (column) can set a wide (high), that is, it can be an absolute representation (value) It is also possible to combine or remove into new cells for relative (percent) * then using Merge and SPLite methods. * Then press from left to right, order from top to bottom, each component is added Put into the corresponding grid. * The components of each grid are: extended filling, optimal size, two ways / ** * Merge cell * @Param StartX start X position * @Param Starty start Y position * @Param Starty @Param ENDX End X Location * @Param Endy End Y Location * / Public Void Merge (int STARTX, INT Starty, int endx, int endy) / ** * Split the current grid, generic mesh * @ PARAM X row * @PARAM Y column number * / / / ** * Get x, y this Box * @Param XX axis position * @Param YY axis position * @return plaid * /

/ *

* CREATED ON 2004-10-27

* /

Package com.fswan.Memo;

Import javax.swing.jbutton;

Import javax.swing.jframe;

Import javax.swing.border.abstractBorder;

Import org.fswan.ui.mutableGridLayout;

/ **

* @Author Swan Fong (Fang Zhiwen)

*

* Sample program for MutableGridLayout layout

* /

Public Class TestLayout

{

Public static void main (string [] args)

{

JFrame JF = New Jframe ("Test Layout"); MutableGridLayout Ml = New MutableGridLayout (3, 4, 5, 5);

ml.getBox (1, 1). Split (2, 3, 10, 10);

Ml.getBox (2, 2) .Setblank (TRUE);

ml.Merge (0, 2, 1, 3);

ml.getBox (0, 2) .split (3, 3);

Ml.getBox (0, 2) .GetBox (0, 0) .split (2, 2);

ml.SetWidth (2,87);

ml.getbox (2,0) .Setfill (MutableGridLayout.PreferRed);

ml.getBox (2,0) .SetAlign (MutableGridLayout.center);

Ml.getBox (2,0) .Setvalign (MutableGridLayout.middle);

Jf.getContentPane (). setLayout (ml);

For (int i = 0; i <30; i )

{

Jf.getContentPane (). Add ("Button i));

}

AbstractBorder D;

Jf.setsize (640, 480);

Jf.setvisible (TRUE);

Jf.setDefaultCloseOperation (jframe.exit_on_close);

}

}

The following is a style written by me and MutableGridLayout. The code is as follows MutableGridLayout Ml = New MutableGridLayout (8, 8, 5, 5); ml.merge (2, 0, 3, 0); ml.getBox (2,0). Split (2,1); ml.merge (1, 1, 3, 1); ml.Merge (5, 1, 7, 1); ml.Merge (5, 2, 7, 2); ml.merge 5, 3, 7, 3); ml.Merge (5, 4, 7, 4); ml.getBox (6, 5) .Setblank (TRUE); ml.getbox (7, 5) .Setblank (TRUE); Ml.getBox (4, 7) .Setblank (TRUE); ml.getBox (5, 7) .Setblank (TRUE); ml.getBox (6, 7) .SetBlank (TRUE); ml.getBox (7, 7) .setblank (TRUE); ml.Merge (0, 7, 1, 7); ml.SetWidth (0,0.1); ml.SetWidth (1,0.15); ml.SetWidth (2, 0.10); ml.SetWidth 3,0.15); ml.SetWidth (4, 0.0.1); ml.SetWidth (5,0.15); ml.Setwidth (6, 0.10); ml.SetWidth (7, 0.15);

转载请注明原文地址:https://www.9cbs.com/read-99029.html

New Post(0)