private void displayOverflow() { int x = getOrientation() == HORIZONTAL ? overflowButton.getLocationOnScreen().x : overflowButton.getLocationOnScreen().x + overflowButton.getWidth(); int y = getOrientation() == HORIZONTAL ? overflowButton.getLocationOnScreen().y + overflowButton.getHeight() : overflowButton.getLocationOnScreen().y; popup.setLocation(x, y); popup.setVisible(true); }
@Override public void actionPerformed (ActionEvent e) { Object source = e.getSource(); if (source instanceof JButton) { JButton button = (JButton) source; popup.show(button, button.getWidth(), 20); } }
@Override public void mousePressed(MouseEvent e) { JPopupMenu menu = new JPopupMenu(); menu.add(new JMenuItem(addNewBoardAction)); menu.add(new JMenuItem(addExistingBoardAction)); menu.show(btnAddBoard, (int) btnAddBoard.getWidth(), (int) btnAddBoard.getHeight()); } });
if (popup.isShowing() && overflowButton.isShowing() && (e.getID() == MouseEvent.MOUSE_MOVED || e.getID() == MouseEvent.MOUSE_EXITED)) { int minX = overflowButton.getLocationOnScreen().x; int maxX_ob = minX + overflowButton.getWidth(); int maxX = getOrientation() == HORIZONTAL ? minX + popup.getWidth() : minX + overflowButton.getWidth() + popup.getWidth(); int minY = overflowButton.getLocationOnScreen().y; int maxY_ob = minY + overflowButton.getHeight();
@ScriptFunction(jsDoc = WIDTH_JSDOC) @Override public int getWidth() { return super.getWidth(); }
void setArrowLocation( int arrowLocation) { this.arrowLocation = arrowLocation; if( arrowLocation == GridBagConstraints.NORTHEAST || arrowLocation == GridBagConstraints.NORTHWEST ) { setBorder( BorderFactory.createEmptyBorder(0, 0, Y_OFFSET, btnDismiss.getWidth())); } else { setBorder( BorderFactory.createEmptyBorder(Y_OFFSET, 0, 0, btnDismiss.getWidth())); } }
@Override public void recive(ActionEvent obj) { confMenu.show(confButton, confButton.getWidth()/2, confButton.getHeight()/2); } });
ImageIcon icon = ...; JButton b = ...; Image im = icon.getImage(); Image im2 = im.getScaledInstance(b.getWidth(), b.getHeight(), ...); b.setIcon(new ImageIcon(im2));
JFrame frame2 = new JFrame("Tauler Joc"); JPanel panell = new JPanel(); ImageIcon icon = new ImageIcon("king.jpg"); JButton jb= new JButton(); jb.setBounds(200,200,700,700); panell.add(jb); // Set image to size of JButton... int offset = jb.getInsets().left; jb.setIcon(resizeIcon(icon, jb.getWidth() - offset, jb.getHeight() - offset)); frame2.add(panell); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JButton button = (JButton) e.getSource(); . . for(int i=0;i<PSIZE;++i){ if (tiles[i] == button){ btnClicks[i] ++; if (btnClicks[i]t % 2 == 0) { button.setIcon(new ImageIcon(OneImageButton.class.getResource("/images/dambee.jpg"))); } else { BufferedImage img = ImageIO.read(...); // learn how to load images from resource. "/images/kiss.jpg" int w = button.getWidth(); int h = button.getHeight(); img = img.getSubimage(w*(i/16), h*(i%16), w, h); button.setIcon(img); } } } }
public void actionPerformed(ActionEvent e) { if (getPopupMenu() != null) if (e.getSource() instanceof JButton) getPopupMenu().show((JButton)e.getSource(), ((JButton)e.getSource()).getWidth() - 5, ((JButton)e.getSource()).getHeight() - 5); } });
public void actionPerformed(ActionEvent e) { JButton jb = (JButton)e.getSource(); JPopupMenu popup = new MessageSliderMenu("Message Slider", ToolTab.this); popup.show(jb, (int)(jb.getWidth() - popup.getPreferredSize().getWidth()) / 2, (int)-popup.getPreferredSize().getHeight()); } };
public void scrollToVisible() { pickColor.scrollRectToVisible(new Rectangle(0, 0, pickColor.getWidth(), pickColor.getHeight())); } private int getFormRow() {
private void showColumnSelectionPopup(final JPopupMenu headerPopup, final JButton cornerButton) { initColumnSelectorItems(); headerPopup.show(cornerButton, cornerButton.getWidth() - headerPopup.getPreferredSize().width, cornerButton.getHeight()); } }
JButton j=new JButton("START"); j.setSize(100,50); j.setLocation(imageLabel.getWidth()/2-j.getWidth()/2, imageLabel.getHeight()/2-j.getHeight()/2); //then add Button into imageLabel imageLabel.add(j);
@Override protected void paintIncreaseHighlight(Graphics g) { Insets insets = scrollbar.getInsets(); Rectangle thumbR = getThumbBounds(); g.setColor(new Color(202,207,203)); if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { int x = insets.left+decrButton.getWidth()/2-2; int y = thumbR.y; int w = 4; int h = incrButton.getY() - y; g.fillRect(x, y, w, h); } }
private void addLines(STreeNode newNode) { JButton newButton = buttons.get(newNode.getID()); int nbX = newButton.getX() + newButton.getWidth()/2; int nbY = newButton.getY() + newButton.getHeight(); for (Iterator<JButton> i = selection.iterator(); i.hasNext(); ) { JButton selButton = i.next(); //I create it a rect but it will in fact be used as x1, y1, x2, y2 for the //draw line. see drawLines. Coordinates coords = new Coordinates( nbX, nbY, selButton.getX() + selButton.getWidth()/2, selButton.getY()); lines.add(coords); } } // addLines
private void shiftButtonsDown(int offset) { for (Iterator<JButton> i = buttons.values().iterator(); i.hasNext(); ) { JButton button = i.next(); button.setBounds( button.getX(), button.getY() + offset, button.getWidth(), button.getHeight()); } // for loop through buttons for (Iterator<Coordinates> k = lines.iterator(); k.hasNext(); ) { Coordinates coords = k.next(); coords.setY1(coords.getY1() + offset); coords.setY2(coords.getY2() + offset); } }// private void shiftButtonsDown(int offset)
/** * recalculates all lines from that node to all its children */ private void recalculateLines(STreeNode node) { Integer id = node.getID(); JButton button = buttons.get(id); int bX = button.getX() + button.getWidth()/2; int bY = button.getY() + button.getHeight(); for (Enumeration<?> e = node.children(); e.hasMoreElements(); ) { STreeNode subNode = (STreeNode) e.nextElement(); Integer sid = subNode.getID(); JButton subButton = buttons.get(sid); Coordinates coords = new Coordinates( bX, bY, subButton.getX() + subButton.getWidth()/2, subButton.getY()); lines.add(coords); } }