// System.out.println(prefHeight
// + ":"
// + bandScrollablePanel.getView()
// .getComponentCount());
JPopupPanel popupPanel = new BandHostPopupPanel(
bandScrollablePanel, new Dimension(
ribbon.getWidth(), prefHeight));
int x = ribbon.getLocationOnScreen().x;
int y = ribbon.getLocationOnScreen().y
+ ribbon.getHeight();
// make sure that the popup stays in bounds
// first, get the graphics config of where the mouse pointer curently is at
PointerInfo pi = MouseInfo.getPointerInfo();
GraphicsDevice gd = pi.getDevice();
GraphicsConfiguration mgc = null;
for (GraphicsConfiguration gc : gd.getConfigurations()) {
if (gc.getBounds().contains(pi.getLocation())) {
mgc = gc;
break;
}
}
if (mgc == null) {
mgc = ribbon.getGraphicsConfiguration();
}
Rectangle scrBounds = mgc.getBounds();
int pw = popupPanel.getPreferredSize().width;
// falling off the left? trim and shift
if (x < scrBounds.x) {
pw = pw - scrBounds.x + x;
x = scrBounds.x;
}
// falling off the right? trim it's width
if ((x + pw) > (scrBounds.x + scrBounds.width)) {
pw = scrBounds.width + scrBounds.x - x;
}
// falling off the bottom? flip it above the tabs
int ph = popupPanel.getPreferredSize().height;
if ((y + ph) > (scrBounds.y + scrBounds.height)) {
y = ribbon.getLocationOnScreen().y - prefHeight;
}
// get the popup and show it
popupPanel.setPreferredSize(new Dimension(
pw, prefHeight));
Popup popup = PopupFactory.getSharedInstance()
.getPopup(taskToggleButton, popupPanel,
x, y);
PopupPanelManager.PopupListener tracker = new PopupPanelManager.PopupListener() {