public class Button extends JApplet implements ActionListener { private JButton button; public void init() { Container container = getContentPane(); container.setLayout(null); container.setBackground(Color.white); button = new JButton("Press Me"); button.setSize(getWidth()/2,20); button.setLocation(getWidth()/2-button.getSize().width/2, getHeight()/2-button.getSize().height/2); container.add(button); button.addActionListener(this); } public void actionPerformed(ActionEvent e) { int width = (button.getSize().width == getWidth()/2) ? getWidth()/4 : getWidth()/2; int height = button.getSize().height; button.setSize(width,height); button.setLocation(getWidth()/2-width/2, getHeight()/2-height/2); } }
new JCheckBox() { JButton button = new JButton(); { button.setModel(getModel()); } @Override protected void paintComponent(Graphics g) { if (!button.getSize().equals(getSize())) { button.setSize(getSize()); } button.paint(g); super.paintComponent(g); } @Override public void setEnabled(boolean b) { super.setEnabled(b); button.setEnabled(b); } };
public void actionPerformed(ActionEvent e) { ZoneSelectionPopup popup = new ZoneSelectionPopup(); popup.show(button, button.getSize().width - popup.getPreferredSize().width, 0); } });
ZoomEntry z = zooms.get(i); JButton b = buttons.get(i); ImageIcon icon = new ImageIcon(ImageUtil.createThumbnail(z.getSnap(),Math.min(z.getSnap().getWidth(),b.getSize().width)-20)); b.setIcon(icon);
m.show(bamViewButton, 0, (int) bamViewButton.getSize().getHeight());
@Override public void actionPerformed(ActionEvent e) { JPopupMenu m = new JPopupMenu(); Set<AppCommHandler> handlers = AppCommRegistry.getInstance().getHandlersForEvent(PatientVariantAnalyzeComm.class); final PatientVariantAnalyzeComm event = new PatientVariantAnalyzeComm(null, patient.getID()); for (final AppCommHandler handler : handlers) { JMenuItem item = new JMenuItem(handler.getHandlerName()); ImageIcon icon = handler.getHandlerIcon(); if (icon != null) { int iconSize = 22; Image img = ViewUtil.getScaledInstance( icon.getImage(), iconSize, iconSize, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true); item.setIcon(new ImageIcon(img)); } ActionListener l = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handler.handleCommEvent(event); } }; item.addActionListener(l); m.add(item); } m.show(dnaIDButton, 0, (int) dnaIDButton.getSize().getHeight()); }
&& e.getID() == MouseEvent.MOUSE_RELEASED && e.getButton() == MouseEvent.BUTTON1) { Dimension size = super.getSize(); if (size != null) { int x = e.getX();
private void applyXfsPosition(final WFSPINFDK pinFDK) { final String method = "applyXfsPosition(WFSPINFDK)"; final VirtualKey key = PINKeyUtil.getVirtualKey(pinFDK.getFDK()); final MenuButton menuButton = getMenuButton(key); if (menuButton == null) { if (LOG.isInfoEnabled()) { LOG.info(method, "Could not find MenuButton for VirtualKey: " + key); } return; } final Dimension frameSize = uiFrame.getSize(); final JButton button = menuButton.getButton(); final Dimension buttonSize = button.getSize(); final int x = calcXPosition(buttonSize, pinFDK.getXPosition(), frameSize.width); final int y = calcYPosition(buttonSize, pinFDK.getYPosition(), frameSize.height); if (LOG.isDebugEnabled()) { LOG.debug(method, "x=" + x + ",y=" + y + ",menuButton=" + menuButton); } button.setBounds(new Rectangle(x, y, buttonSize.width, buttonSize.height)); }