synchronized (target.getTreeLock()) { int hgap = getHgap(); int vgap = getVgap(); int w = target.getWidth();
@Override public Dimension getPreferredSize() { Dimension size = getParent().getSize(); FlowLayout layout = (FlowLayout) getLayout(); Insets insets = getInsets(); // This isn't exact, but hopefully it's close enough int panelWidth = size.width - insets.left - insets.right; int panelHeight = size.height - insets.top - insets.bottom; int height = insets.top + insets.bottom + layout.getVgap(); for (Component c : getComponents()) { Dimension cSize = c.getPreferredSize(); height += cSize.height + layout.getVgap(); } height = Math.max(height, panelHeight); // fill the panel if it wouldn't already Dimension prefSize = new Dimension(panelWidth, height); return prefSize; }
@ScriptFunction(jsDoc = VGAP_JSDOC) public int getVgap() { return ((FlowLayout) super.getLayout()).getVgap(); }
public LayoutManager getLayout() { LayoutManager togo = null; if (exemplar instanceof FlowLayout) { FlowLayout exflow = (FlowLayout)exemplar; togo = new FlowLayout(exflow.getAlignment(), exflow.getHgap(), exflow.getVgap()); } else { throw new AssertionException("Unrecognised layout manager " + exemplar); } return togo; } public int getHeight() {
synchronized (target.getTreeLock()) { int hgap = getHgap(); int vgap = getVgap(); int w = target.getWidth();
@Override public Dimension getPreferredSize() { Dimension size = getParent().getSize(); FlowLayout layout = (FlowLayout) getLayout(); Insets insets = getInsets(); // This isn't exact, but hopefully it's close enough int x = layout.getHgap() + insets.left; int y = layout.getVgap(); int rowHeight = 0; for (Component c : getComponents()) { Dimension cSize = c.getPreferredSize(); if (x + cSize.width + layout.getHgap() > size.width - insets.right && x > 0) { x = 0; y += rowHeight + layout.getVgap(); rowHeight = 0; } x += cSize.width + layout.getHgap(); rowHeight = Math.max(cSize.height, rowHeight); } y += rowHeight + layout.getVgap(); y += getInsets().top; y += getInsets().bottom; Dimension prefSize = new Dimension(size.width, y); return prefSize; }
@Override public Dimension getPreferredSize() { FlowLayout layout = (FlowLayout) getLayout(); Insets insets = getInsets(); // This isn't exact, but hopefully it's close enough int availableWidth = getPanel().getAvailableWidth() - insets.left - insets.right; int height = insets.top + insets.bottom + layout.getVgap(); int rowHeight = 0; int rowWidth = insets.left + layout.getHgap() + insets.right; for (Component c : getComponents()) { Dimension cSize = c.getPreferredSize(); if (rowWidth + cSize.width + layout.getHgap() - 5 > availableWidth && rowWidth > 0) { height += rowHeight + layout.getVgap(); rowHeight = 0; rowWidth = insets.left + layout.getHgap() + insets.right; } rowWidth += cSize.width + layout.getHgap(); rowHeight = Math.max(cSize.height, rowHeight); } height += rowHeight; Dimension prefSize = new Dimension(availableWidth, height); return prefSize; }
private int getPreferredHeight() { int rv = 0; for (int k = 0, count = getComponentCount(); k < count; k++) { Component comp = getComponent(k); Rectangle r = comp.getBounds(); int height = r.y + r.height; if (height > rv) rv = height; } rv += ((FlowLayout) getLayout()).getVgap(); return rv; } }
@Override public Dimension getPreferredSize() { FlowLayout layout = (FlowLayout) getLayout(); Insets insets = getInsets(); // This isn't exact, but hopefully it's close enough int availableWidth = getPanel().getAvailableWidth() - insets.left - insets.right - 10; int height = insets.top + insets.bottom + layout.getVgap(); int rowHeight = 0; int rowWidth = insets.left + layout.getHgap() + insets.right; for (Component c : getComponents()) { Dimension cSize = c.getPreferredSize(); if (rowWidth + cSize.width + layout.getHgap() - 5 > availableWidth && rowWidth > 0) { height += rowHeight + layout.getVgap(); rowHeight = 0; rowWidth = insets.left + layout.getHgap() + insets.right; } rowWidth += cSize.width + layout.getHgap(); rowHeight = Math.max(cSize.height, rowHeight); } height += rowHeight; Dimension prefSize = new Dimension(availableWidth, height); return prefSize; }
private int getPreferredHeight() { int rv = 0; for (int k = 0, count = getComponentCount(); k < count; k++) { Component comp = getComponent(k); Rectangle r = comp.getBounds(); int height = r.y + r.height; if (height > rv) { rv = height; } } rv += ((FlowLayout) getLayout()).getVgap(); return rv; } }
private final FlowLayout layout = new FlowLayout(); private final int hGap = layout.getHgap(); private final int vGap = layout.getVgap(); private final Dimension size;