@Override public Dimension getSize() { if (myPopup != null) { final Window popupWindow = SwingUtilities.windowForComponent(myContent); return popupWindow.getSize(); } else { return myForcedSize; } }
@Override public void moveToFitScreen() { if (myPopup == null) return; final Window popupWindow = SwingUtilities.windowForComponent(myContent); Rectangle bounds = popupWindow.getBounds(); ScreenUtil.moveRectangleToFitTheScreen(bounds); setLocation(bounds.getLocation()); setSize(bounds.getSize(), false); }
private void setSizeAndDimensions( @NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); // table.setPreferredSize(dimension); // table.setMaximumSize(dimension); // table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4 /* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
public static Window setSize(JComponent content, final Dimension size) { final Window popupWindow = SwingUtilities.windowForComponent(content); final Point location = popupWindow.getLocation(); popupWindow.setLocation(location.x, location.y); Insets insets = content.getInsets(); if (insets != null) { size.width += insets.left + insets.right; size.height += insets.top + insets.bottom; } content.setPreferredSize(size); popupWindow.pack(); return popupWindow; }
private RelativePoint relativePointByQuickSearch(final DataContext dataContext) { Rectangle dominantArea = PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE.getData(dataContext); if (dominantArea != null) { final Component focusedComponent = getWndManager().getFocusedComponent(myProject); Window window = SwingUtilities.windowForComponent(focusedComponent); JLayeredPane layeredPane; if (window instanceof JFrame) { layeredPane = ((JFrame) window).getLayeredPane(); } else if (window instanceof JDialog) { layeredPane = ((JDialog) window).getLayeredPane(); } else if (window instanceof JWindow) { layeredPane = ((JWindow) window).getLayeredPane(); } else { throw new IllegalStateException( "cannot find parent window: project=" + myProject + "; window=" + window); } return relativePointWithDominantRectangle(layeredPane, dominantArea); } return JBPopupFactory.getInstance().guessBestPopupLocation(dataContext); }