public void layoutContainer(Container parent) { Dimension ourSize = preferredLayoutSize(parent), // Does the following do something useful? // And shouldn't we cater to real instead of maximum sizes? // This way, if a VerticallyLaidout component had a particular size forced upon it, // wouldn't we neglect to scale down to using minimum sizes so long as its maximum // size was bigger than our preferred? all: [Davis] maxSize = parent.getMaximumSize(), size = parent.getSize(); Insets isets = parent.getInsets(); Dimension compSize; int n = parent.getComponentCount(); int y; boolean usingPreferredSize = true; if (ourSize.width > maxSize.width || ourSize.height > maxSize.height) { ourSize = minimumLayoutSize(parent); usingPreferredSize = false; } switch (verticalAlignment) { case TOP: y = isets.top; break; case BOTTOM: y = (size.height - ourSize.height); break; default: // assume MIDDLE y = (size.height - ourSize.height) / 2 + isets.top; break; } for (int i = 0; i < n; i++) { Component c = parent.getComponent(i); compSize = usingPreferredSize ? c.getPreferredSize() : c.getMinimumSize(); switch (horizontalAlignment) { case LEFT: c.setBounds(isets.left, y, compSize.width, compSize.height); break; case RIGHT: c.setBounds( ourSize.width - isets.right - compSize.width + isets.left, y, compSize.width, compSize.height); break; default: // assume CENTER c.setBounds( (ourSize.width - isets.left - isets.right - compSize.width + isets.left) / 2, y, compSize.width, compSize.height); } y += compSize.height + vgap; } }
/** 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 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; }
private static void drawSelection(JTree tree, Graphics g, final int width) { int y = 0; final int[] rows = tree.getSelectionRows(); final int height = tree.getRowHeight(); for (int row : rows) { final TreeCellRenderer renderer = tree.getCellRenderer(); final Object value = tree.getPathForRow(row).getLastPathComponent(); if (value == null) continue; final Component component = renderer.getTreeCellRendererComponent(tree, value, false, false, false, row, false); if (component.getFont() == null) { component.setFont(tree.getFont()); } g.translate(0, y); component.setBounds(0, 0, width, height); boolean wasOpaque = false; if (component instanceof JComponent) { final JComponent j = (JComponent) component; if (j.isOpaque()) wasOpaque = true; j.setOpaque(false); } component.paint(g); if (wasOpaque) { ((JComponent) component).setOpaque(true); } y += height; g.translate(0, -y); } }
private static void drawSelection(JTable table, int column, Graphics g, final int width) { int y = 0; final int[] rows = table.getSelectedRows(); final int height = table.getRowHeight(); for (int row : rows) { final TableCellRenderer renderer = table.getCellRenderer(row, column); final Component component = renderer.getTableCellRendererComponent( table, table.getValueAt(row, column), false, false, row, column); g.translate(0, y); component.setBounds(0, 0, width, height); boolean wasOpaque = false; if (component instanceof JComponent) { final JComponent j = (JComponent) component; if (j.isOpaque()) wasOpaque = true; j.setOpaque(false); } component.paint(g); if (wasOpaque) { ((JComponent) component).setOpaque(true); } y += height; g.translate(0, -y); } }
public void componentMoved(ComponentEvent evt) { Component component = evt.getComponent(); Point point = component.getLocation(); if (point.y < 0) { component.setBounds(point.x, 0, component.getWidth(), component.getHeight()); } }
/** * Lays out the container in the specified container. * * @param parent the component which needs to be laid out */ public void layoutContainer(Container parent) { synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); int ncomponents = parent.getComponentCount(); if (ncomponents == 0) { return; } // Total parent dimensions Dimension size = parent.getSize(); int totalW = size.width - (insets.left + insets.right); int totalH = size.height - (insets.top + insets.bottom); // Cell dimensions, including padding int totalCellW = totalW / gridSize.width; int totalCellH = totalH / gridSize.height; // Cell dimensions, without padding int cellW = (totalW - ((gridSize.width + 1) * hgap)) / gridSize.width; int cellH = (totalH - ((gridSize.height + 1) * vgap)) / gridSize.height; for (int i = 0; i < ncomponents; i++) { Component c = parent.getComponent(i); Rectangle rect = (Rectangle) compTable.get(c); if (rect != null) { int x = insets.left + (totalCellW * rect.x) + hgap; int y = insets.top + (totalCellH * rect.y) + vgap; int w = (cellW * rect.width) - hgap; int h = (cellH * rect.height) - vgap; c.setBounds(x, y, w, h); } } } }
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 void layoutContainer(Container target) { Insets insets = target.getInsets(); int ncomponents = target.getComponentCount(); int top = 0; int left = insets.left; Dimension tps = target.getPreferredSize(); Dimension targetSize = target.getSize(); Component comp; Dimension ps; if (horizontalOrientation == Orientation.CENTER) left = left + (targetSize.width / 2) - (tps.width / 2); if (horizontalOrientation == Orientation.RIGHT) left = left + targetSize.width - tps.width; for (int i = 0; i < ncomponents; i++) { comp = target.getComponent(i); if (comp.isVisible()) { ps = comp.getPreferredSize(); if (verticalOrientation == Orientation.CENTER) top = (targetSize.height / 2) - (ps.height / 2); else if (verticalOrientation == Orientation.TOP) top = insets.top; else if (verticalOrientation == Orientation.BOTTOM) top = targetSize.height - ps.height - insets.bottom; comp.setBounds(left, top, ps.width, ps.height); left += ps.width + gap; } } }
@Override public void layoutContainer(Container parent) { int width = parent.getWidth(); int height = parent.getHeight(); Component toolbar = parent.getComponent(0); Dimension toolbarSize = toolbar.isVisible() ? toolbar.getPreferredSize() : new Dimension(); toolbar.setBounds(0, 0, width, toolbarSize.height); parent.getComponent(1).setBounds(0, toolbarSize.height, width, height - toolbarSize.height); }
private void doRohu(final Component cc, final Dimension dim, final int x, final int y) { if (cc != null) { final Dimension v = rozmer(dim, cc); final int x0 = x < 0 ? -v.width - x : x; final int y0 = y < 0 ? -v.height - y : y; cc.setBounds(x0, y0, v.width, v.height); // System.out.println(x0 + " " + y0 + v); } }
public void doLayout() { super.doLayout(); if (getScrollbarDisplayPolicy() == SCROLLBARS_NEVER) { // Use this class's calculateChildSize() and re-do layout of child Component c = getComponent(0); Dimension cs = calculateChildSize(); Insets i = getInsets(); c.setBounds(i.left, i.top, cs.width, cs.height); } }
@Override public void doLayout() { int x = 0; for (int i = 0; i < getComponentCount(); i++) { final Component each = getComponent(i); final Dimension eachSize = each.getPreferredSize(); each.setBounds(x, 0, eachSize.width, getHeight()); x += each.getBounds().width; } }
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 void measureLayout(Container target, Dimension dimension, int type) { int count = target.getComponentCount(); if (count > 0) { Insets insets = target.getInsets(); Dimension size = target.getSize(); int x = 0; int y = 0; int maxWidth = 0; int maxHeight = 0; double radius = Math.min( size.width - insets.left - insets.right, size.height - insets.top - insets.bottom) / 2; Dimension[] sizes = new Dimension[count]; for (int i = 0; i < count; i++) { Component c = target.getComponent(i); if (includeComponent(c)) { Dimension d = getComponentSize(c, type); int w = d.width; int h = d.height; sizes[i] = d; maxWidth = Math.max(maxWidth, w); maxHeight = Math.max(maxHeight, h); } } if (dimension != null) { dimension.width = (int) (2 * radius - maxWidth); dimension.height = (int) (2 * radius - maxHeight); } else { int mx = (size.width - insets.left - insets.right - 2 * hMargin) / 2; int my = (size.height - insets.top - insets.bottom - 2 * vMargin) / 2; x = 0; y = 0; radius -= Math.max(maxWidth, maxHeight) / 2; for (int i = 0; i < count; i++) { Component c = target.getComponent(i); if (includeComponent(c)) { Dimension d = sizes[i]; int w = d.width; int h = d.height; double angle = 2 * Math.PI * i / count; x = mx + (int) (Math.sin(angle) * radius); y = my - (int) (Math.cos(angle) * radius); c.setBounds(insets.left + hMargin + x - w / 2, insets.top + vMargin + y - h / 2, w, h); } } } } }
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); } }
public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); if (parent.getComponentOrientation().isLeftToRight()) { int x = insets.left; for (Component component : parent.getComponents()) { Dimension ps = component.getPreferredSize(); component.setBounds( x, insets.top, ps.width, parent.getHeight() - insets.top - insets.bottom); x += ps.width - overlap; } } else { int x = parent.getWidth() - insets.right; for (Component component : parent.getComponents()) { Dimension ps = component.getPreferredSize(); component.setBounds( x - ps.width, insets.top, ps.width, parent.getHeight() - insets.top - insets.bottom); x += overlap - ps.width; } } }
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); }
@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); } }
/** * Lays out the container in the specified panel. * * @param parent the component which needs to be laid out */ public void layoutContainer(Container parent) { for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements(); ) { Component comp = (Component) e.nextElement(); AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp); Dimension size = comp.getPreferredSize(); int width = ac.getWidth(); if (width == -1) width = size.width; int height = ac.getHeight(); if (height == -1) height = size.height; comp.setBounds(ac.x, ac.y, width, height); } }
@Override public void doLayout() { super.doLayout(); Component child = getComponentCount() == 1 ? getComponent(0) : null; if (child instanceof JBTabsPresentation) { if (!((JBTabsPresentation) child).isHideTabs()) { Rectangle bounds = child.getBounds(); bounds.y--; bounds.height++; child.setBounds(bounds); } } }
/** * Method to set the mouse dragged actions * * @param e */ public void mouseDragged(MouseEvent e) { if (dragging) { Point p = e.getPoint(); int x = p.x - offset.x; int y = p.y - offset.y; Dimension d = selectedComponent.getSize(); selectedComponent.setBounds(x, y, d.width, d.height); if (!selected) { activePanel.repaint(); selected = false; } glassPanel.repaint(); } }
@Override public void layoutContainer(final Container parent) { assert parent.getComponentCount() == 2; // 1. info; 2. progress Component infoPanel = parent.getComponent(0); Component progressPanel = parent.getComponent(1); int progressPrefWidth = progressPanel.getPreferredSize().width; final Dimension size = parent.getSize(); int maxProgressWidth = (int) (size.width * 0.8); int minProgressWidth = (int) (size.width * 0.5); if (progressPrefWidth > myProgressWidth) { myProgressWidth = progressPrefWidth; } if (myProgressWidth > maxProgressWidth) { myProgressWidth = maxProgressWidth; } if (myProgressWidth < minProgressWidth) { myProgressWidth = minProgressWidth; } infoPanel.setBounds(0, 0, size.width - myProgressWidth, size.height); progressPanel.setBounds(size.width - myProgressWidth, 0, myProgressWidth, size.height); }
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; } }
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(); }
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); } }
@Override public void layoutContainer(Container parent) { for (Component component : this.componentMap.keySet()) { Resize r = this.componentMap.get(component); Rectangle rect = r.resize(parent); if (this.padding != 0) { rect = new Rectangle( rect.x + padding, rect.y + padding, rect.width - padding * 2, rect.height - padding * 2); } component.setBounds(rect); } }
/* * (non-Javadoc) * * @see java.awt.LayoutManager#layoutContainer(java.awt.Container) */ @Override public void layoutContainer(final Container c) { final Insets in = c.getInsets(); final int x1 = in.left; final int x2 = c.getWidth() - in.right; final int y1 = in.top; final int y2 = c.getHeight() - in.bottom; final Dimension dim = new Dimension(x2 - x1, y2 - y1); // System.out.println(dim + " " + c.getWidth() + " " + c.getHeight()); doRohu(sz, dim, x1, y1); doRohu(jz, dim, x1, -y2); doRohu(sv, dim, -x2, y1); doRohu(jv, dim, -x2, -y2); podklad.setBounds(x1, y1, dim.width, dim.height); }
@Override public void layoutContainer(Container aContainer) { layouted .entrySet() .stream() .forEach( (entry) -> { Component comp = entry.getKey(); if (comp.isVisible()) { Dimension containerSize = aContainer.getSize(); MarginConstraints constraints = entry.getValue(); Rectangle bounds = constraints.toRectangle(containerSize.width, containerSize.height); comp.setBounds(bounds); } }); }
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(); } }