public void removeGridComponent(Component component) { GridLayout l = (GridLayout) getContentPane().getLayout(); // Remove sections if necessary int threshold = (l.getColumns() - 1) * (l.getRows() - 1); if (threshold > 0 && threshold == getContentPane().getComponentCount() - 1) { getContentPane().setLayout(new GridLayout(l.getColumns() - 1, l.getRows() - 1)); } getContentPane().remove(component); validate(); } }
public void addGridComponent(Component component) { GridLayout l = (GridLayout) getContentPane().getLayout(); // Make more sections if necessary int availableSections = l.getColumns() * l.getRows(); if (availableSections == getContentPane().getComponentCount()) { getContentPane().setLayout(new GridLayout(l.getColumns() + 1, l.getRows() + 1)); } getContentPane().add(component); validate(); }
/** * Removes the component from the panel with the buttons. * * @param comp the component to remove */ public void removeFromButtonsPanel(Component comp) { m_LayoutButtons.setRows(m_LayoutButtons.getRows() - 1); m_PanelButtons.remove(comp); } }
/** * Removes the component from the panel with the Widgets. * * @param comp the component to remove */ public void removeFromWidgetsPanel(Component comp) { if (m_LayoutWidgets != null) m_LayoutWidgets.setRows(m_LayoutWidgets.getRows() - 1); m_PanelWidgets.remove(comp); }
/** * Removes the component from the panel with the buttons. * * @param comp the component to remove */ public void removeFromButtonsPanel(Component comp) { m_LayoutButtons.setRows(m_LayoutButtons.getRows() - 1); m_PanelButtons.remove(comp); } }
JPanel m = new JPanel(); GridLayout gridLayout = new GridLayout(3, 3,0,0); m.setLayout( gridLayout); for (int i = 0; i < gridLayout.getRows(); i++) { for (int ii = 0; ii < gridLayout.getColumns(); ii++) { JPanel p = new JPanel(); p.add(new JButton("X")); m.add(p, i, ii); } } frame.add(m);
/** * Removes the component from the panel with the Widgets. * * @param comp the component to remove */ public void removeFromWidgetsPanel(Component comp) { if (m_LayoutWidgets != null) m_LayoutWidgets.setRows(m_LayoutWidgets.getRows() - 1); m_PanelWidgets.remove(comp); }
@ScriptFunction public int getRows() { return layout.getRows(); }
/** * Adds the component to the panel with the buttons. * * @param comp the component to add */ public void addToButtonsPanel(Component comp) { removeFromButtonsPanel(comp); m_LayoutButtons.setRows(m_LayoutButtons.getRows() + 1); m_PanelButtons.add(comp); }
/** * Adds the component to the panel with the buttons. * * @param comp the component to add */ public void addToButtonsPanel(Component comp) { removeFromButtonsPanel(comp); m_LayoutButtons.setRows(m_LayoutButtons.getRows() + 1); m_PanelButtons.add(comp); }
/** * Adds the component to the panel with the Widgets. * * @param comp the component to add * @param index the index where to add the component, -1 adds the * component at the end */ public void addToWidgetsPanel(Component comp, int index) { removeFromWidgetsPanel(comp); if (m_LayoutWidgets != null) m_LayoutWidgets.setRows(m_LayoutWidgets.getRows() + 1); if (index != -1) m_PanelWidgets.add(comp, index); else m_PanelWidgets.add(comp); }
/** * Adds the component to the panel with the Widgets. * * @param comp the component to add * @param index the index where to add the component, -1 adds the * component at the end */ public void addToWidgetsPanel(Component comp, int index) { removeFromWidgetsPanel(comp); if (m_LayoutWidgets != null) m_LayoutWidgets.setRows(m_LayoutWidgets.getRows() + 1); if (index != -1) m_PanelWidgets.add(comp, index); else m_PanelWidgets.add(comp); }
public void actionPerformed(ActionEvent e) { gl.setRows(gl.getRows() + 1); frame.add(new JTextField(10)); frame.add(new JTextField(10));
@ScriptFunction(jsDoc = REMOVE_JSDOC, params = {"component"}) @Override public void remove(JComponent aComp) { for (int i = 0; i < layout.getRows(); i++) { for (int j = 0; j < layout.getColumns(); j++) { int index = i * layout.getColumns() + j; if (super.getComponent(index) == aComp) { super.remove(index); super.add(new PlaceHolder(), index); super.revalidate(); super.repaint(); return; } } } }
@ScriptFunction @Undesignable @Override public JComponent[] children() { List<JComponent> ch = new ArrayList<>(); for (int i = 0; i < layout.getRows(); i++) { for (int j = 0; j < layout.getColumns(); j++) { int index = i * layout.getColumns() + j; JComponent comp = (JComponent) super.getComponent(index); if (comp instanceof PlaceHolder) { ch.add(null); } else { ch.add(comp); } } } return ch.toArray(new JComponent[]{}); }
public void renderMeasurements (final @Nonnull String[][] measurements) { assert EventQueue.isDispatchThread(); innerPanel.removeAll(); gridLayout.setColumns(measurements[0].length); gridLayout.setRows(measurements.length); gridLayout.setHgap(1); gridLayout.setVgap(1); for (int row = 0; row < gridLayout.getRows(); row++) { for (int column = 0; column < gridLayout.getColumns(); column++) { innerPanel.add(new MeasurementPanel(measurements[row][column])); } } innerPanel.validate(); } }
public void renderMeasurements (final @Nonnull String[][] measurements) { assert EventQueue.isDispatchThread(); innerPanel.removeAll(); gridLayout.setColumns(measurements[0].length); gridLayout.setRows(measurements.length); gridLayout.setHgap(1); gridLayout.setVgap(1); for (int row = 0; row < gridLayout.getRows(); row++) { for (int column = 0; column < gridLayout.getColumns(); column++) { innerPanel.add(new MeasurementPanel(measurements[row][column])); } } innerPanel.validate(); } }
Insets insets = parent.getInsets(); int ncomponents = parent.getComponentCount(); int nrows = getRows(); int ncols = getColumns(); boolean ltr = parent.getComponentOrientation().isLeftToRight();
for (int row=0; row<grid.getRows(); row++) { Component c = grid.getComponent(col, row); grid.setComponentAlignment(c, Alignment.TOP_CENTER);
@Test public void testLayouts() { final GridLayout result = (GridLayout) JPanelBuilder.builder() .gridLayout(1, 2) .build() .getLayout(); assertThat(result.getRows(), is(1)); assertThat(result.getColumns(), is(2)); assertThat(JPanelBuilder.builder() .gridBagLayout(2) .build() .getLayout(), instanceOf(GridBagLayout.class)); assertThat(JPanelBuilder.builder() .flowLayout() .build() .getLayout(), instanceOf(FlowLayout.class)); assertThat(JPanelBuilder.builder() .borderLayout() .build() .getLayout(), instanceOf(BorderLayout.class)); }