|
|
@ -125,10 +125,13 @@ public class PopupMenuContainer extends JPanel { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Popup createPopup(final JPopupMenu popupMenu, final int posX, final int posY, final int maxHeight) { |
|
|
|
public Popup createPopup(final JPopupMenu popupMenu, final int posX, final int posY, |
|
|
|
|
|
|
|
final int maxWidth, final int maxHeight) { |
|
|
|
final Dimension prefSize = popupMenu.getPreferredSize(); |
|
|
|
final Dimension prefSize = popupMenu.getPreferredSize(); |
|
|
|
uninstallListeners(); |
|
|
|
uninstallListeners(); |
|
|
|
if (maxHeight <= 0 || prefSize.height <= maxHeight) { |
|
|
|
boolean exceedsHorizontalSize = (maxHeight > 0 && prefSize.height > maxHeight); |
|
|
|
|
|
|
|
boolean exceedsVerticalSize = (maxWidth > 0 && prefSize.width > maxWidth); |
|
|
|
|
|
|
|
if (!exceedsHorizontalSize && !exceedsVerticalSize) { |
|
|
|
setBounds(0, 0, prefSize.width, prefSize.height); |
|
|
|
setBounds(0, 0, prefSize.width, prefSize.height); |
|
|
|
popupMenu.setBorderPainted(true); |
|
|
|
popupMenu.setBorderPainted(true); |
|
|
|
return PopupFactory.getSharedInstance().getPopup(popupMenu.getInvoker(), popupMenu, posX, posY); |
|
|
|
return PopupFactory.getSharedInstance().getPopup(popupMenu.getInvoker(), popupMenu, posX, posY); |
|
|
@ -139,14 +142,24 @@ public class PopupMenuContainer extends JPanel { |
|
|
|
if (popupMenu.getComponentCount() > 0) { |
|
|
|
if (popupMenu.getComponentCount() > 0) { |
|
|
|
increment = Math.max(1, popupMenu.getComponent(0).getPreferredSize().height / 2); |
|
|
|
increment = Math.max(1, popupMenu.getComponent(0).getPreferredSize().height / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
JScrollBar bar = scrollPane.getVerticalScrollBar(); |
|
|
|
JScrollBar verticalBar = scrollPane.getVerticalScrollBar(); |
|
|
|
bar.setValue(bar.getMinimum()); |
|
|
|
verticalBar.setValue(verticalBar.getMinimum()); |
|
|
|
bar.setUnitIncrement(increment); |
|
|
|
verticalBar.setUnitIncrement(increment); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JScrollBar horizontalBar = scrollPane.getHorizontalScrollBar(); |
|
|
|
|
|
|
|
horizontalBar.setValue(horizontalBar.getMinimum()); |
|
|
|
|
|
|
|
horizontalBar.setUnitIncrement(increment); |
|
|
|
|
|
|
|
|
|
|
|
view.removeAll(); |
|
|
|
view.removeAll(); |
|
|
|
view.add(popupMenu, BorderLayout.CENTER); |
|
|
|
view.add(popupMenu, BorderLayout.CENTER); |
|
|
|
setBorder(popupMenu.getBorder()); |
|
|
|
setBorder(popupMenu.getBorder()); |
|
|
|
popupMenu.setBorderPainted(false); |
|
|
|
popupMenu.setBorderPainted(false); |
|
|
|
setPreferredSize(new Dimension(prefSize.width + bar.getPreferredSize().width, maxHeight)); |
|
|
|
Dimension constraintSize = new Dimension(prefSize); |
|
|
|
|
|
|
|
if (exceedsHorizontalSize) constraintSize.width += verticalBar.getPreferredSize().width; |
|
|
|
|
|
|
|
if (exceedsVerticalSize) constraintSize.height += horizontalBar.getPreferredSize().height; |
|
|
|
|
|
|
|
if (maxWidth > 0) constraintSize.width = Math.min(constraintSize.width, maxWidth); |
|
|
|
|
|
|
|
if (maxHeight > 0) constraintSize.height = Math.min(constraintSize.height, maxHeight); |
|
|
|
|
|
|
|
setPreferredSize(constraintSize); |
|
|
|
return PopupFactory.getSharedInstance().getPopup(popupMenu.getInvoker(), this, posX, posY); |
|
|
|
return PopupFactory.getSharedInstance().getPopup(popupMenu.getInvoker(), this, posX, posY); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|