final JPopupMenu menu = new JPopupMenu(); menu.add(...whatever...); final JButton button = new JButton(); button.setText("My Menu"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { menu.show(button, button.getBounds().x, button.getBounds().y + button.getBounds().height); } });
@Override public boolean contains(int x, int y) { return this.closeButton.getBounds().contains(x, y); }
Rectangle bounds = button.getBounds(); bounds.x -= 10; bounds.y -= 10;
@Override public void actionPerformed(ActionEvent e) { final JPopupMenu menu = new JPopupMenu(); JMenuItem menuItemEdit = new JMenuItem("Auto track number"); menu.add(menuItemEdit).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Tools.autoTrackNumber(tagFieldsModel); tagFieldsModel.sort(); tagsTable.revalidate(); tagsTable.repaint(); } }); menu.show(tools, 0, tools.getBounds().height); } });
JComponent comp = Box.createVerticalBox(); final JComponent upper = new JPanel(); final JButton upperChild = new JButton("happy in upper"); upper.add(upperChild); final JComponent lower = new JPanel(); final JButton lowerChild = new JButton("unhappy in lower"); lower.add(lowerChild); comp.add(upper); comp.add(lower); LayerUI<JComponent> ui = new LayerUI<JComponent>() { @Override public void paint(Graphics g, JComponent c) { super.paint(g, c); Rectangle u = SwingUtilities.convertRectangle(upper, upperChild.getBounds(), c); Rectangle l = SwingUtilities.convertRectangle(lower, lowerChild.getBounds(), c); g.setColor(Color.RED); g.drawLine(u.x, u.y + u.height, l.x, l.y); } }; JLayer<JComponent> layer = new JLayer<JComponent>(comp, ui);
@Override public void actionPerformed(ActionEvent e) { JPopupMenu menu = new JPopupMenu("New File"); List<CodeParserPlugin> plugins = new ArrayList<CodeParserPlugin>(); plugins.addAll(Plugins.getCodeParserPlugins()); Collections.sort(plugins, new PluginSorter()); for (CodeParserPlugin plugin : plugins) { menu.add(new NewFileAction(plugin, tabbedPane)); } menu.show(newFileButton, 0, newFileButton.getBounds().height); } });
@Override public void actionPerformed(ActionEvent e) { JPopupMenu menu = new JPopupMenu("Open File"); List<CodeParserPlugin> plugins = new ArrayList<CodeParserPlugin>(); plugins.addAll(Plugins.getCodeParserPlugins()); Collections.sort(plugins, new PluginSorter()); for (CodeParserPlugin plugin : plugins) { menu.add(new OpenFileAction(plugin, tabbedPane)); } menu.show(openFileButton, 0, openFileButton.getBounds().height); } });
public class Click { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final JFrame f = new JFrame("Click pos"); f.setSize(640, 480); final JButton b = new JButton("Click Me!"); b.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { final JButton bb = (JButton) e.getSource(); final Rectangle bbox = bb.getBounds(); final int x = bbox.x + e.getX(); final int y = bbox.y + e.getY(); JOptionPane.showMessageDialog(f, "pos: " + x + " " + y); } }); f.getContentPane().add(b, BorderLayout.SOUTH); f.setVisible(true); } }); } }
/** * Paints the divider. * * @param g Description of Parameter */ public void paint(Graphics g) { //Paint the border. //Border border = getBorder(); //if (border != null) { Dimension size = getSize(); //border.paintBorder(this, g, 0, 0, size.width, size.height); skin.getSplitPane().paintGutter(g, splitPane, size); if (leftButton != null) { Rectangle bounds = leftButton.getBounds(); Graphics glb = g.create(bounds.x, bounds.y, bounds.width, bounds.height); leftButton.paint(glb); } if (rightButton != null) { Rectangle bounds = rightButton.getBounds(); Graphics grb = g.create(bounds.x, bounds.y, bounds.width, bounds.height); rightButton.paint(grb); } skin.getSplitPane().paintThumb(g, splitPane, size); }
@Override public void mouseReleased(MouseEvent event) { // Do nothing if the mouse was released inside the toggle button. Point mousePositionOnScreen = MouseInfo.getPointerInfo().getLocation(); Rectangle toggleBoundsOnScreen = getComponentToggleTimeMenuButton().getBounds(); toggleBoundsOnScreen.setLocation(getComponentToggleTimeMenuButton().getLocationOnScreen()); if (toggleBoundsOnScreen.contains(mousePositionOnScreen)) { return; } if (timeMenuPanel != null) { timeMenuPanel.mouseReleasedFromToggleButtonOutsideButton(); } } });
Rectangle bounds = listButton.getBounds(); switch (tabPlacement) { case TOP:
(int) buttonEdit.getBounds().getMaxX() + 5, 0, BasePanel.WIDGET_BUTTON_WIDTH,
rect = iconifyButton.getBounds();
Rectangle bounds = listButton.getBounds(); Point p = listButton.getLocationOnScreen(); bounds.x = p.x;
((JideTabbedPane.NoFocusButton) _closeButtons[i]).setIndex(i); if (!bounds.equals(_closeButtons[i].getBounds())) { _closeButtons[i].setBounds(bounds);
/** * Paint the background for a tab scroll button. * * @param ss the tab subregion SynthContext. * @param g the Graphics context. * @param scrollButton the button to paint. */ protected void paintScrollButtonBackground(SeaGlassContext ss, Graphics g, JButton scrollButton) { Rectangle tabRect = scrollButton.getBounds(); int x = tabRect.x; int y = tabRect.y; int height = tabRect.height; int width = tabRect.width; boolean flipSegments = (orientation == ControlOrientation.HORIZONTAL && !tabPane.getComponentOrientation().isLeftToRight()); SeaGlassLookAndFeel.updateSubregion(ss, g, tabRect); tabPane.putClientProperty("JTabbedPane.Tab.segmentPosition", ((scrollButton == scrollBackwardButton) ^ flipSegments) ? "first" : "last"); int oldState = tabContext.getComponentState(); ButtonModel model = scrollButton.getModel(); int isPressed = model.isPressed() && model.isArmed() ? PRESSED : 0; int buttonState = SeaGlassLookAndFeel.getComponentState(scrollButton) | isPressed; tabContext.setComponentState(buttonState); tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g, x, y, width, height, -1, tabPlacement); tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g, x, y, width, height, -1, tabPlacement); tabContext.setComponentState(oldState); }