/** Lays out the container in the specified panel. */ public void layoutContainer(Container target) { synchronized (target.getTreeLock()) { Insets insets = target.getInsets(); Dimension dim = target.getSize(); int fullHeight = dim.height; int bottom = dim.height - insets.bottom - 1; int top = 0 + insets.top; int left = insets.left; int maxPosition = dim.width - (insets.left + insets.right) - hgap; int right = dim.width - insets.right; maxPosition = right; int height = bottom - top; int size = actions.size(); int w, h; if ((grip != null) && grip.isVisible()) { Dimension d = grip.getPreferredSize(); grip.setBounds(left, top + vgap, d.width, bottom - top - 2 * vgap); left += d.width; left += hgap; } for (int i = 0; i < size; i++) { left += hgap; Component comp = (Component) actions.elementAt(i); Dimension d; Dimension minSize = comp.getMinimumSize(); if (i == size - 1) d = comp.getMaximumSize(); else d = comp.getPreferredSize(); w = d.width; h = Math.min(height, d.height); if ((left < maxPosition) && (left + w > maxPosition)) { if (maxPosition - left >= minSize.width) w = maxPosition - left; } comp.setBounds(left, (fullHeight - d.height) / 2, w, h); // if (i == size - 1) // d = comp.getMaximumSize(); // else // d = comp.getPreferredSize(); // if ((left + d.width) > right) // w = right - left; // else // w = d.width; // h = Math.min (height, d.height); // comp.setBounds (left, (fullHeight - d.height)/2, w, h); left += d.width; } } }
public void layoutContainer(Container parent) { Dimension size = parent.getSize(); Insets insets = parent.getInsets(); int itop = insets.top; int ileft = insets.left; int ibottom = insets.bottom; int iright = insets.right; int rightWidth = right.getPreferredSize().width; int bottomHeight = bottom.getPreferredSize().height; int centerWidth = size.width - rightWidth - ileft - iright; int centerHeight = size.height - bottomHeight - itop - ibottom; center.setBounds(ileft, itop, centerWidth, centerHeight); right.setBounds(ileft + centerWidth, itop, rightWidth, centerHeight); // Lay out all status components, in order Enumeration status = leftOfScrollBar.elements(); while (status.hasMoreElements()) { Component comp = (Component) status.nextElement(); Dimension dim = comp.getPreferredSize(); comp.setBounds(ileft, itop + centerHeight, dim.width, bottomHeight); ileft += dim.width; } bottom.setBounds( ileft, itop + centerHeight, size.width - rightWidth - ileft - iright, bottomHeight); }
public boolean editCellAt(int index, EventObject e) { if (editor != null && !editor.stopCellEditing()) return false; if (index < 0 || index >= getModel().getSize()) return false; if (!isCellEditable(index)) return false; if (editorRemover == null) { KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); editorRemover = new CellEditorRemover(fm); fm.addPropertyChangeListener("permanentFocusOwner", editorRemover); // NOI18N } if (editor != null && editor.isCellEditable(e)) { editorComp = prepareEditor(index); if (editorComp == null) { removeEditor(); return false; } editorComp.setBounds(getCellBounds(index, index)); add(editorComp); editorComp.validate(); editingIndex = index; editor.addCellEditorListener(this); return true; } return false; }
protected void paintEditor(Graphics g) { Component component = grid.getEditorComponent(); if (component == null) { return; } Rectangle cellBounds = grid.getCellBounds(grid.getEditingRow(), grid.getEditingColumn()); component.setBounds(cellBounds); component.validate(); component.requestFocus(); }
public static void setRelativeBounds( @NotNull Component parent, @NotNull Rectangle bounds, @NotNull Component child, @NotNull Container validationParent) { validationParent.add(parent); parent.setBounds(bounds); parent.validate(); child.setLocation(SwingUtilities.convertPoint(child, 0, 0, parent)); validationParent.remove(parent); }
public void layoutContainer(Container target) { // System.out.println("Laying out container " + target); super.layoutContainer(target); if (free != null) { // what is free?? Point loc = free.getLocation(); Dimension sz = free.getSize(); // System.out.println("Laying out free component " + free); free.setBounds(loc.x, loc.y, sz.width, sz.height); } }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if (c instanceof Container) { Insets borderInsets = border.getBorderInsets(c); Insets insets = getBorderInsets(c); int temp = (insets.top - borderInsets.top) / 2; border.paintBorder(c, g, x, y + temp, width, height - temp); Dimension size = comp.getPreferredSize(); Rectangle rect = new Rectangle(OFFSET, 0, size.width, size.height); SwingUtilities.paintComponent(g, comp, (Container) c, rect); comp.setBounds(rect); } }
protected void changeBounds( Component source, int direction, Rectangle bounds, Point pressed, Point current) { // Start with original locaton and size int x = bounds.x; int y = bounds.y; int width = bounds.width; int height = bounds.height; // Resizing the West or North border affects the size and location if (WEST == (direction & WEST)) { int drag = getDragDistance(pressed.x, current.x, snapSize.width); int maximum = Math.min(width + x, maximumSize.width); drag = getDragBounded(drag, snapSize.width, width, minimumSize.width, maximum); x -= drag; width += drag; } if (NORTH == (direction & NORTH)) { int drag = getDragDistance(pressed.y, current.y, snapSize.height); int maximum = Math.min(height + y, maximumSize.height); drag = getDragBounded(drag, snapSize.height, height, minimumSize.height, maximum); y -= drag; height += drag; } // Resizing the East or South border only affects the size if (EAST == (direction & EAST)) { int drag = getDragDistance(current.x, pressed.x, snapSize.width); Dimension boundingSize = getBoundingSize(source); int maximum = Math.min(boundingSize.width - x, maximumSize.width); drag = getDragBounded(drag, snapSize.width, width, minimumSize.width, maximum); width += drag; } if (SOUTH == (direction & SOUTH)) { int drag = getDragDistance(current.y, pressed.y, snapSize.height); Dimension boundingSize = getBoundingSize(source); int maximum = Math.min(boundingSize.height - y, maximumSize.height); drag = getDragBounded(drag, snapSize.height, height, minimumSize.height, maximum); height += drag; } source.setBounds(x, y, width, height); source.validate(); }
private static JButton getButton(JList<String> list, Point pt, int index) { Component c = list.getCellRenderer().getListCellRendererComponent(list, "", index, false, false); Rectangle r = list.getCellBounds(index, index); c.setBounds(r); // c.doLayout(); //may be needed for mone LayoutManager pt.translate(-r.x, -r.y); Component b = SwingUtilities.getDeepestComponentAt(c, pt.x, pt.y); if (b instanceof JButton) { return (JButton) b; } else { return null; } }
public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); Component c; c = parent.getComponent(0); if (c.isVisible()) { c.setBounds(insets.left + 152, insets.top + 64, 176, 24); } c = parent.getComponent(1); if (c.isVisible()) { c.setBounds(insets.left + 152, insets.top + 96, 176, 24); } c = parent.getComponent(2); if (c.isVisible()) { c.setBounds(insets.left + 72, insets.top + 8, 184, 32); } c = parent.getComponent(3); if (c.isVisible()) { c.setBounds(insets.left + 16, insets.top + 64, 128, 24); } c = parent.getComponent(4); if (c.isVisible()) { c.setBounds(insets.left + 16, insets.top + 96, 128, 24); } c = parent.getComponent(5); if (c.isVisible()) { c.setBounds(insets.left + 56, insets.top + 176, 96, 32); } c = parent.getComponent(6); if (c.isVisible()) { c.setBounds(insets.left + 176, insets.top + 176, 96, 32); } c = parent.getComponent(7); if (c.isVisible()) { c.setBounds(insets.left + 152, insets.top + 128, 176, 24); } c = parent.getComponent(8); if (c.isVisible()) { c.setBounds(insets.left + 16, insets.top + 128, 128, 24); } }
private void dispatchEvent(MouseEvent me) { if (rect != null && rect.contains(me.getX(), me.getY())) { Point pt = me.getPoint(); pt.translate(-offset, 0); comp.setBounds(rect); comp.dispatchEvent( new MouseEvent( comp, me.getID(), me.getWhen(), me.getModifiers(), pt.x, pt.y, me.getClickCount(), me.isPopupTrigger(), me.getButton())); if (!comp.isValid()) container.repaint(); } }
public void layoutContainer(Container parent) { Dimension size = parent.getSize(); Dimension captionSize = caption.getPreferredSize(); caption.setBounds(PADDING, PADDING, captionSize.width, captionSize.height); // make all buttons the same size Dimension buttonSize = cancelButton.getPreferredSize(); buttonSize.width = Math.max(buttonSize.width, prevButton.getPreferredSize().width); buttonSize.width = Math.max(buttonSize.width, nextButton.getPreferredSize().width); // cancel button goes on far left cancelButton.setBounds( PADDING, size.height - buttonSize.height - PADDING, buttonSize.width, buttonSize.height); // prev and next buttons are on the right prevButton.setBounds( size.width - buttonSize.width * 2 - 6 - PADDING, size.height - buttonSize.height - PADDING, buttonSize.width, buttonSize.height); nextButton.setBounds( size.width - buttonSize.width - PADDING, size.height - buttonSize.height - PADDING, buttonSize.width, buttonSize.height); // calculate size for current page Rectangle currentPageBounds = new Rectangle(); currentPageBounds.x = PADDING; currentPageBounds.y = PADDING * 2 + captionSize.height; currentPageBounds.width = size.width - currentPageBounds.x - PADDING; currentPageBounds.height = size.height - buttonSize.height - currentPageBounds.y - PADDING * 2; for (int i = 0; i < pages.length; i++) { Component page = pages[i]; page.setBounds(currentPageBounds); page.setVisible(i == currentPage); } }
public void layoutContainer(Container target) { Insets insets = target.getInsets(); Dimension size = target.getSize(); Dimension compMax = new Dimension(0, 0); int maxheight = size.height - (insets.top + insets.bottom + vgap * 2); int nmembers = target.getComponentCount(); int visiblecount = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { ++visiblecount; Dimension d = m.getPreferredSize(); compMax.width = Math.max(compMax.width, d.width); compMax.height = Math.max(compMax.height, d.height); } } if (visiblecount > 0) { int nrows = Math.max(1, (maxheight + compMax.height / 4) / compMax.height); int ncols = (visiblecount + nrows - 1) / nrows; int row = 0, col = 0, currComp = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); int x = insets.left + hgap + col * (compMax.width + hgap); int y = insets.top + vgap + row * (compMax.height + vgap); m.setBounds(x, y, d.width, d.height); // move index to next component ++currComp; if (++row >= nrows) { row = 0; ++col; } } } } repaint(); }
/** Add Component Without a Layout Manager (Absolute Positioning) */ private void addComponent(Container container, Component c, int x, int y, int width, int height) { c.setBounds(x, y, width, height); container.add(c); }