@Override public void layoutContainer(Container target) { super.layoutContainer(target); int width = LightScrollPane.this.getWidth(); int height = LightScrollPane.this.getHeight(); LightScrollPane.this.scrollPane.setBounds(0, 0, width, height); int scrollBarSize = THUMB_SIZE; int cornerOffset = LightScrollPane.this.verticalScrollBar.isVisible() && LightScrollPane.this.horizontalScrollBar.isVisible() ? scrollBarSize : 0; if (LightScrollPane.this.verticalScrollBar.isVisible()) { LightScrollPane.this.verticalScrollBar.setBounds( LightScrollPane.this.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT ? 0 : width - scrollBarSize, 0, scrollBarSize, height - cornerOffset ); } if (LightScrollPane.this.horizontalScrollBar.isVisible()) { LightScrollPane.this.horizontalScrollBar.setBounds( 0, height - scrollBarSize, width - cornerOffset, scrollBarSize ); } } });
@Override public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int width = parent.getWidth() - insets.left - insets.right; int height = parent.getHeight() - insets.top - insets.bottom; int x = insets.left; int y = insets.top; int position = 0; for (Component comp : parent.getComponents()) { if ((comp instanceof JScrollBar) && comp.isVisible()) { JScrollBar scrollBar = (JScrollBar) comp; Dimension dim = scrollBar.getPreferredSize(); scrollBar.setBounds(x + width - dim.width, y, dim.width, height); width -= dim.width; position = scrollBar.getValue(); } } y -= position; for (Component comp : parent.getComponents()) { if (!(comp instanceof JScrollBar) && comp.isVisible()) { Dimension pref = comp.getPreferredSize(); comp.setBounds(x, y, width, pref.height); y += pref.height; } } } }
@Override public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int width = parent.getWidth() - insets.left - insets.right; int height = parent.getHeight() - insets.top - insets.bottom; int x = insets.left; int y = insets.top; int position = 0; for(Component comp : parent.getComponents()) { if((comp instanceof JScrollBar) && comp.isVisible()) { JScrollBar scrollBar = (JScrollBar) comp; Dimension dim = scrollBar.getPreferredSize(); scrollBar.setBounds(x + width-dim.width, y, dim.width, height); width -= dim.width; position = scrollBar.getValue(); } } y -= position; for(Component comp : parent.getComponents()) { if(!(comp instanceof JScrollBar) && comp.isVisible()) { Dimension pref = comp.getPreferredSize(); comp.setBounds(x, y, width, pref.height); y += pref.height; } } } }
scrollBar.setBounds(x + width - dim.width, y, dim.width, height); width -= dim.width; position = scrollBar.getValue();
public class DrawTest { public static void main(String[] args){ JFrame frame = new JFrame("SSCCE"); frame.setLayout(new BorderLayout()); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final DrawComp d = new DrawComp(); final JScrollBar hbar,vbar; hbar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 500); vbar = new JScrollBar(JScrollBar.VERTICAL, 0, 1, 0, 500); frame.setLayout(null); frame.add(d); frame.add(hbar); frame.add(vbar); d.setBounds(0, 0, 300, 300); vbar.setBounds(460, 0, 20, 480); frame.setVisible(true); vbar.addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { d.setLocation(d.getX(), -vbar.getValue()); } }); } }
@Override public void layoutContainer(Container parent) { JScrollPane scrollPane = (JScrollPane)parent; Rectangle availR = scrollPane.getBounds(); availR.x = availR.y = 0; Insets insets = parent.getInsets(); availR.x = insets.left; availR.y = insets.top; availR.width -= insets.left + insets.right; availR.height -= insets.top + insets.bottom; Rectangle vsbR = new Rectangle(); vsbR.width = 5; vsbR.height = availR.height; vsbR.x = availR.x + availR.width - vsbR.width; vsbR.y = availR.y; if(viewport != null) { viewport.setBounds(availR); } if(vsb != null) { vsb.setVisible(true); vsb.setBounds(vsbR); } } });
@Override public void layoutContainer(Container parent) { super.layoutContainer(parent); if (lowerLeft != null && hsb != null) { Dimension llp = lowerLeft.getPreferredSize(); //Insets insets = parent.getInsets(); lowerLeft.setBounds(hsb.getX(), hsb.getY(), llp.width, hsb.getHeight()); hsb.setBounds(hsb.getX() + llp.width, hsb.getY(), hsb.getWidth() - llp.width, hsb.getHeight()); } }
final int delta = hsbPref.height; vsbBounds.height -= delta; vsb.setBounds(vsbBounds); if (isLeftToRight) { lowerRight.setBounds(vsbBounds.x, vsbBounds.y + vsbBounds.height, vsbBounds.width, delta); hsbBounds.x += delta; hsb.setBounds(hsbBounds); if (isLeftToRight) { lowerRight.setBounds(hsbBounds.x + hsbBounds.width, hsbBounds.y, delta, hsbBounds.height);
public void doLayout() { int height = getHeight(); if (height > 0) for (Component component : getComponents()) { JScrollBar scroller = (JScrollBar)component; int column = table.convertColumnIndexToView(getColumn(scroller)); Rectangle rect = table.getTableHeader().getHeaderRect(column); scroller.setBounds(rect.x, 0, rect.width, height); scroller.doLayout(); } } public Dimension getPreferredSize() {
/*************************************************************************** * * Lays out the scrollbars in their correct position. * **************************************************************************/ private void layoutScrollBars () { if (scrollBarsVisible && ((previousWidth != getWidth()) || (previohsHeight != getHeight()))) { horizontalScrollBar.setBounds(0, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness, scrollbarThickness); verticalScrollBar.setBounds(getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness); filler.setBounds(getWidth() - scrollbarThickness, getHeight() - scrollbarThickness, scrollbarThickness, scrollbarThickness); previousWidth = getWidth(); previohsHeight = getHeight(); } }
public class CustomScrollPaneLayout extends ScrollPaneLayout { @Override public void layoutContainer(Container parent) { super.layoutContainer(parent); JScrollBar scrollBar = getHorizontalScrollBar(); if (lowerLeft == null || !lowerLeft.isVisible() || scrollBar == null) return; Dimension size = lowerLeft.getPreferredSize(); Rectangle bounds = lowerLeft.isVisible() ? lowerLeft.getBounds() : scrollBar.getBounds(); if (size.width > bounds.getWidth()) { int right = scrollBar.getX()+scrollBar.getWidth(); if (size.width + scrollBar.getMinimumSize().width > right) size.width = right - scrollBar.getMinimumSize().width; if (bounds.x + size.width < scrollBar.getX()) size.width = scrollBar.getX() - bounds.x; lowerLeft.setBounds(bounds.x, bounds.y, size.width, bounds.height); int x = bounds.x + size.width; scrollBar.setBounds(x, bounds.y, right - x, bounds.height); } lowerLeft.setVisible(true); } }
private int layoutVerticalScrollbar() { int vw; if (needVerticalScrollbar()) { verticalSB.setVisible(true); Dimension vsbSize = verticalSB.getPreferredSize(); Dimension spSize = getAWTComponent().getSize(); verticalSB.setBounds(spSize.width - vsbSize.width, 0, vsbSize.width, spSize.height); vw = spSize.width - vsbSize.width; } else { verticalSB.setVisible(false); vw = getAWTComponent().getWidth(); } return vw; }
private int layoutHorizontalScrollbar() { int vh; if (needHorizontalScrollbar()) { horizontalSB.setVisible(true); Dimension hsbSize = horizontalSB.getPreferredSize(); Dimension spSize = getAWTComponent().getSize(); if (verticalSB.isVisible()) { spSize.width -= verticalSB.getWidth(); int vsbH = verticalSB.getHeight() - hsbSize.height; verticalSB.setSize(new Dimension(verticalSB.getWidth(), vsbH)); } horizontalSB.setBounds(0, spSize.height - hsbSize.height, spSize.width, hsbSize.height); vh = spSize.height - hsbSize.height; } else { verticalSB.setVisible(false); vh = getAWTComponent().getHeight(); } return vh; }
Rectangle vBounds = vertical.getBounds(); dw += (1 + borderDelta); vertical.setBounds(vBounds.x + 1 + borderDelta, vBounds.y + 1 - 2 * borderWidth, vBounds.width, vBounds.height + 2 * borderWidth); dh += (1 + borderDelta); Rectangle hBounds = horizontal.getBounds(); horizontal.setBounds(hBounds.x + 1 - 2 * borderWidth, hBounds.y + 1, hBounds.width + 2 * borderWidth, hBounds.height); dw += (1 + borderDelta); Rectangle vBounds = vertical.getBounds(); vertical.setBounds(vBounds.x - 1 - borderDelta, vBounds.y - 1 - borderDelta, vBounds.width, vBounds.height + 2 * borderWidth); dh += (1 + borderDelta); Rectangle hBounds = horizontal.getBounds(); horizontal.setBounds(hBounds.x - 1 - borderDelta, hBounds.y + 1 + borderDelta, hBounds.width + 2
Rectangle scrollbarBounds = hsb.getBounds(); scrollbarBounds.width = viewportBounds.x + viewportBounds.width - scrollbarBounds.x; hsb.setBounds(scrollbarBounds); Rectangle scrollbarBounds = vsb.getBounds(); scrollbarBounds.height = viewportBounds.y + viewportBounds.height - scrollbarBounds.y; vsb.setBounds(scrollbarBounds);
Rectangle vBounds = vertical.getBounds(); dw += (1 + borderDelta); vertical.setBounds(vBounds.x + 1 + borderDelta, vBounds.y + 1 - 2 * borderWidth, vBounds.width, vBounds.height + 2 * borderWidth); dh += (1 + borderDelta); Rectangle hBounds = horizontal.getBounds(); horizontal.setBounds(hBounds.x + ((scrollPane.getRowHeader() == null) ? 1 : 2) - 2 * borderWidth, hBounds.y + 1, hBounds.width dw += (1 + borderDelta); Rectangle vBounds = vertical.getBounds(); vertical.setBounds(vBounds.x - 1 - borderDelta, vBounds.y - 1 - borderDelta, vBounds.width, vBounds.height + 2 * borderWidth); Rectangle hBounds = horizontal.getBounds(); horizontal .setBounds( hBounds.x - ((scrollPane.getRowHeader() == null) ? 1