@Override public void layoutContainer(Container parent) { int x = 0; for (Component c : parent.getComponents()) { x += ITEM_PADDING; int height = c.getPreferredSize().height; if (height > TITLEBAR_SIZE) { height = TITLEBAR_SIZE; } c.setBounds(x, (TITLEBAR_SIZE - height) / 2, TITLEBAR_SIZE, height); x += TITLEBAR_SIZE; } } });
/** * 取得合并后的单元格的大小,这个方法需要计算,首先 是取得一个没有合并的最小单元格的JTableHeader 的大小 * 通过Renderer取得组件 * * @return */ public Dimension getSize(JTable table) { Component comp = renderer.getTableCellRendererComponent(table, getHeaderValue(), false, false, -1, -1); int height = comp.getPreferredSize().height; int width = 0; // 宽度需要计算合并的还要加上间隙 Enumeration<Object> enumeration = vector.elements(); while (enumeration.hasMoreElements()) { Object obj = enumeration.nextElement(); if (obj instanceof TableColumn) { TableColumn aColumn = (TableColumn) obj; width += aColumn.getWidth(); width += margin; } else { width += ((ColumnGroup) obj).getSize(table).width; } } return new Dimension(width, height); }
Insets insets = target.getInsets(); if (insets == null){ insets = new Insets(0, 0, 0, 0); Component c = target.getComponent(i); if (c.isVisible()) { Dimension d = c.getPreferredSize(); if ((x == 0) || ((x + d.width) <= maxwidth)) { return new Dimension(reqdWidth+insets.left+insets.right, y); Component c = target.getComponent(i); if (c.isVisible()) { found_one = true; Dimension d = c.getPreferredSize(); minx = Math.min(minx, d.width); miny = Math.min(miny, d.height); return new Dimension(minx, miny); return new Dimension(0, 0);
@Override public Dimension getPreferredSize() { Component[] comps = getAllComponents(); Insets insets = getInsets(); int width = null == insets ? 0 : insets.left + insets.right; int height = null == insets ? 0 : insets.top + insets.bottom; for (int i = 0; i < comps.length; i++) { Component comp = comps[i]; if (!comp.isVisible()) { continue; } width += getOrientation() == HORIZONTAL ? comp.getPreferredSize().width : comp.getPreferredSize().height; height = Math.max( height, getOrientation() == HORIZONTAL ? comp.getPreferredSize().height : comp.getPreferredSize().width ); } if(overflowToolbar.getComponentCount() > 0) { width += getOrientation() == HORIZONTAL ? overflowButton.getPreferredSize().width : overflowButton.getPreferredSize().height; } Dimension dim = getOrientation() == HORIZONTAL ? new Dimension(width, height) : new Dimension(height, width); return dim; }
@Override public Dimension preferredLayoutSize(Container parent) { int height = 0; int width = 0; Component[] components = parent.getComponents(); for(int index = 0; index < components.length; index++) { Component child = components[index]; Dimension size = child.getPreferredSize(); width = Math.max(width, size.width); height += size.height; if(index > 0) { height += gap; } } Insets insets = parent.getInsets(); width += insets.left + insets.right; height += insets.top + insets.bottom; return new Dimension(width, height); }
for(Component comp : getComponents()) { if(!(comp instanceof JScrollBar)) { Dimension preferredSize = comp.getPreferredSize(); width = Math.max(width, preferredSize.width); if(unit < 0){ int height = heightMargin + extent; setPopupSize(new Dimension(width, height)); Dimension pref = comp.getPreferredSize(); dim.width = Math.max(dim.width, pref.width); dim.height += pref.height; Insets insets = parent.getInsets(); dim.height = Math.min(dim.height + insets.top + insets.bottom, visibleAmount); Insets insets = parent.getInsets(); dim.height = Math.min(dim.height + insets.top + insets.bottom, visibleAmount); Insets insets = parent.getInsets(); Dimension pref = comp.getPreferredSize(); comp.setBounds(x, y, width, pref.height); y += pref.height;
@Override public Dimension getPreferredSize() {//size frame purposefully smaller return new Dimension(100, 100); return img; } else { component.setSize(component.getPreferredSize()); layoutComponent(component); BufferedImage img = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TRANSLUCENT); return new Dimension(width, height);
@Override public Dimension preferredLayoutSize(Container c) { Insets ins = c.getInsets(); int pw = 0; int gap = getBandGap(); for (Component regComp : ribbon.getTaskbarComponents()) { pw += regComp.getPreferredSize().width; pw += gap; } return new Dimension(pw + ins.left + ins.right, getTaskbarHeight() + ins.top + ins.bottom); }
@Override public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int x = insets.left; int y = insets.top; int width = parent.getWidth() - insets.left - insets.right; for(Component child : parent.getComponents()) { Dimension preferredSize = child.getPreferredSize(); int height = preferredSize.height; child.setBounds(x, y, width, height); y += child.getPreferredSize().height + gap; } }
sPosition = firstComponent.getPreferredSize().height; } else { sPosition = firstComponent.getPreferredSize().width; sPosition = d.height - splitter.getPreferredSize().width - secondComponent.getPreferredSize().height; } else { sPosition = d.width - splitter.getPreferredSize().height - secondComponent.getPreferredSize().width; int splitterSize = splitter.getPreferredSize().height; firstComponent.setBounds(new Rectangle(0, 0, d.width, sPosition)); splitter.setBounds(new Rectangle(0, sPosition, d.width, splitterSize)); secondComponent.setBounds( new Rectangle(0, sPosition + splitterSize, d.width, d.height - sPosition - splitterSize) ); } else { int splitterSize = splitter.getPreferredSize().width;
public static class MyCardLayout extends CardLayout { @Override public Dimension preferredLayoutSize(Container parent) { Component current = findCurrentComponent(parent); if (current != null) { Insets insets = parent.getInsets(); Dimension pref = current.getPreferredSize(); pref.width += insets.left + insets.right; pref.height += insets.top + insets.bottom; return pref; } return super.preferredLayoutSize(parent); } public Component findCurrentComponent(Container parent) { for (Component comp : parent.getComponents()) { if (comp.isVisible()) { return comp; } } return null; } }
private int layoutHorizComponent(Component comp, Dimension toolbarDim, Insets insets, int left) { if(comp.isVisible()) { Dimension d = comp.getPreferredSize(); comp.setBounds(left, insets.top, d.width, toolbarDim.height - insets.top - insets.bottom); left += d.width + gap; } return left; }
@Override public Dimension preferredLayoutSize(Container parent) { Component current = findCurrentComponent(parent); if (current != null) { Insets insets = parent.getInsets(); Dimension pref = current.getPreferredSize(); pref.width += insets.left + insets.right; pref.height += insets.top + insets.bottom; return pref; } return super.preferredLayoutSize(parent); }
public Dimension preferredLayoutSize(Container parent) { int width = 0; int height = 0; if (firstComponent != null) { Dimension d = firstComponent.getPreferredSize(); width = d.width; height = d.height; } if (secondComponent != null) { Dimension d = secondComponent.getPreferredSize(); if (splitType == VERTICAL) { int splitterSize = splitter.getPreferredSize().height; if (width < d.width) { width = d.width; } height += (splitterSize + d.height); } else { int splitterSize = splitter.getPreferredSize().width; if (height < d.height) { height = d.height; } width += (splitterSize + d.width); } } return new Dimension(width, height); }
final Insets insets = parent.getInsets(); final int ncomponents = parent.getComponentCount(); int nrows = getRows(); final Component comp = parent.getComponent(i); final Dimension d = comp.getPreferredSize(); d.width = (int) (sw * d.width); d.height = (int) (sh * d.height); parent.getComponent(i).setBounds(x, y, w[c], h[r]);
int w = getOrientation() == HORIZONTAL ? overflowButton.getIcon().getIconWidth() + 4 : getWidth() - getInsets().left - getInsets().right; int h = getOrientation() == HORIZONTAL ? getHeight() - getInsets().top - getInsets().bottom : overflowButton.getIcon().getIconHeight() + 4; overflowButton.setMaximumSize(new Dimension(w, h)); overflowButton.setMinimumSize(new Dimension(w, h)); overflowButton.setPreferredSize(new Dimension(w, h)); if( !comp.isVisible() ) { continue; int size = getOrientation() == HORIZONTAL ? comp.getPreferredSize().width : comp.getPreferredSize().height; if (sizeSoFar + size <= maxSize) { sizeSoFar += size;
@Override public Dimension preferredLayoutSize(final Container cont) { synchronized(cont.getTreeLock()) { int w = 0, h = 0; for(final Component comp : cont.getComponents()) { final Dimension d = comp.getPreferredSize(); w += gap + d.width; h = Math.max(h, d.height); } final Insets in = cont.getInsets(); return new Dimension(in.left + Math.max(w - gap, 0) + in.right, in.top + h + in.bottom); } }
@Override public void layoutContainer(final Container cont) { synchronized(cont.getTreeLock()) { int x = 0; final Insets in = cont.getInsets(); for(final Component comp : cont.getComponents()) { final Dimension d = comp.getPreferredSize(); comp.setBounds(in.left + x, in.top, d.width, d.height); x += gap + d.width; } } } }
@Override public void layoutContainer(Container parent) { if (comp != null) { Dimension cdim = comp.getPreferredSize(); Dimension pdim = parent.getSize(); int x = (pdim.width / 2) - (cdim.width / 2); int y = (pdim.height / 2) - (cdim.height / 2); comp.setBounds(x, y, cdim.width, cdim.height); } }
private int getSideWidth(Component comp) { if(comp == null) return 0; if(comp.isVisible()) return comp.getPreferredSize().width; return 0; }