/** * Adds a component to the layout. * * @param name The name of the component to add. * @param component the component to add to the layout. */ public void addLayoutComponent(String name, Component component) { if (way == X_AXIS || (way == LINE_AXIS && component.getComponentOrientation().isHorizontal()) || (way == PAGE_AXIS && !component.getComponentOrientation().isHorizontal())) grid.setColumns(grid.getColumns() + 1); else grid.setRows(grid.getRows() + 1); }
public void componentResized(ComponentEvent e) { GridLayout layout = (GridLayout) getLayout(); for (Component component : getComponents()) { int cellSize = Math.max(getWidth(), getHeight()); component.setSize(cellSize / layout.getColumns(), cellSize / layout.getRows()); ((JLabel) component) .setFont(((JLabel) component).getFont().deriveFont((float) cellSize / layout.getRows())); } }
/** * Removes a component from the layout. * * @param component The component to remove from the layout. */ public void removeLayoutComponent(Component component) { grid.removeLayoutComponent(component); if (way == X_AXIS || (way == LINE_AXIS && component.getComponentOrientation().isHorizontal()) || (way == PAGE_AXIS && !component.getComponentOrientation().isHorizontal())) grid.setColumns(grid.getColumns() - 1); else grid.setRows(grid.getRows() - 1); }