|
|
|
package com.fanruan.api.design.ui.layout;
|
|
|
|
|
|
|
|
import com.fr.design.layout.TableLayout;
|
|
|
|
import com.fr.design.layout.TableLayoutHelper;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author richie
|
|
|
|
* @version 10.0
|
|
|
|
* Created by richie on 2019-08-28
|
|
|
|
* 表格布局
|
|
|
|
* <pre> {@code
|
|
|
|
* double p = TableLayoutKit.PREFERRED;
|
|
|
|
* double f = TableLayoutKit.FILL;
|
|
|
|
* double[] rowSize = new double[]{p, p, p, f};
|
|
|
|
* double[] columnSize = new double[]{p, f};
|
|
|
|
* JComponent[][] comps = new JComponent[][]{
|
|
|
|
* {new JLabel(), new JButton()},
|
|
|
|
* {new JLabel(), new JButton()},
|
|
|
|
* {new JLabel(), new JButton()}
|
|
|
|
* };
|
|
|
|
* JPanel = TableLayoutKit.createTableLayoutPane(comps, rowSize, columnSize);
|
|
|
|
* }
|
|
|
|
* </pre>
|
|
|
|
*/
|
|
|
|
public class TableLayoutKit {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按需计算尺寸
|
|
|
|
*/
|
|
|
|
public static final double PREFERRED = TableLayout.PREFERRED;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按充满计算尺寸
|
|
|
|
*/
|
|
|
|
public static final double FILL = TableLayout.FILL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 不填充
|
|
|
|
*/
|
|
|
|
public static final int FILL_NONE = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 最后一列自动充满
|
|
|
|
*/
|
|
|
|
public static final int FILL_LAST_COLUMN = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 填充最后一行
|
|
|
|
*/
|
|
|
|
public static final int FILL_LAST_ROW = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 同时填充最后一行和最后一列
|
|
|
|
*/
|
|
|
|
public static final int FILL_LAST_COL_AND_ROW = 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建一个简单的表格布局并把组件添加到布局容器中
|
|
|
|
*
|
|
|
|
* @param components 组件
|
|
|
|
* @param rowSize 行尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @param columnSize 列尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @return 按要求的布局添加好组件的容器
|
|
|
|
*/
|
|
|
|
public static JPanel createTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize) {
|
|
|
|
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建一个简单的表格布局并把组件添加到布局容器中
|
|
|
|
*
|
|
|
|
* @param components 组件
|
|
|
|
* @param rowSize 行尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @param columnSize 列尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @param gap 垂直和水平间隙
|
|
|
|
* @return 按要求的布局添加好组件的容器
|
|
|
|
*/
|
|
|
|
public static JPanel createCommonTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize, double gap) {
|
|
|
|
|
|
|
|
return TableLayoutHelper.createCommonTableLayoutPane(components, rowSize, columnSize, gap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建一个简单的表格布局并把组件添加到布局容器中
|
|
|
|
*
|
|
|
|
* @param components 组件
|
|
|
|
* @param fillType 填充策略
|
|
|
|
* @param horizontalGap 水平间隙
|
|
|
|
* @param verticalGap 垂直间隙
|
|
|
|
* @return 按要求的布局添加好组件的容器
|
|
|
|
* @see TableLayoutKit#FILL_NONE
|
|
|
|
* @see TableLayoutKit#FILL_LAST_COLUMN
|
|
|
|
* @see TableLayoutKit#FILL_LAST_ROW
|
|
|
|
* @see TableLayoutKit#FILL_LAST_COL_AND_ROW
|
|
|
|
*/
|
|
|
|
public static JPanel createGapTableLayoutPane(Component[][] components, int fillType, double horizontalGap, double verticalGap) {
|
|
|
|
return TableLayoutHelper.createGapTableLayoutPane(components, fillType, horizontalGap, verticalGap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建一个简单的表格布局并把组件添加到布局容器中
|
|
|
|
*
|
|
|
|
* @param components 组件
|
|
|
|
* @param rowSize 行尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @param columnSize 列尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @param horizontalGap 水平间隙
|
|
|
|
* @param verticalGap 垂直间隙
|
|
|
|
* @return 按要求的布局添加好组件的容器
|
|
|
|
*/
|
|
|
|
public static JPanel createGapTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize, double horizontalGap, double verticalGap) {
|
|
|
|
|
|
|
|
return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, horizontalGap, verticalGap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建一个简单的表格布局并把组件添加到布局容器中
|
|
|
|
*
|
|
|
|
* @param components 组件
|
|
|
|
* @param rowSize 行尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @param columnSize 列尺寸信息,可以是固定的数值,也可以是PREFERRED或者FILL常量
|
|
|
|
* @param rowCount 行数量
|
|
|
|
* @param horizontalGap 水平间隙
|
|
|
|
* @param verticalGap 垂直间隙
|
|
|
|
* @return 按要求的布局添加好组件的容器
|
|
|
|
*/
|
|
|
|
public static JPanel createGapTableLayoutPane(Component[][] components,
|
|
|
|
double[] rowSize, double[] columnSize, int[][] rowCount, double horizontalGap, double verticalGap) {
|
|
|
|
return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, horizontalGap, verticalGap);
|
|
|
|
}
|
|
|
|
}
|