@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; }
private int computeVisibleButtons() { if (isShowing()) { 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)); int showingButtons = 0; // all that return true from isVisible() int visibleButtons = 0; // all visible that fit into the given space (maxSize) Insets insets = getInsets(); if( null != insets ) { sizeSoFar = getOrientation() == HORIZONTAL ? insets.left+insets.right : insets.top+insets.bottom;