@Override public void paint (Graphics g) { super.paint(g); // SKIP g.setColor(palette.getColorForValue(ImportType.SKIP)); int xSkipLoc = skipLabel.getLocation().x + LABEL_CUBE_DISTANCE; int ySkipLoc = skipLabel.getLocation().y; g.fillRect(xSkipLoc, ySkipLoc, COLORCUBE_WIDTH, COLORCUBE_HEIGHT); // IMPORT g.setColor(palette.getColorForValue(ImportType.IMPORT)); int xImportLoc = importLabel.getLocation().x + LABEL_CUBE_DISTANCE; int yImportLoc = importLabel.getLocation().y; g.fillRect(xImportLoc, yImportLoc, COLORCUBE_WIDTH, COLORCUBE_HEIGHT); }
Point loc = label.getLocation(); Point pos = label.getLocationOnScreen(); Window win = SwingUtilities.getWindowAncestor(this); Point wLoc = win.getLocation(); Point rPos = SwingUtilities.convertPoint(label, label.getLocation(), win); JRootPane rootPane = SwingUtilities.getRootPane(this); Point cPos = SwingUtilities.convertPoint(label, loc, rootPane.getContentPane());
@ScriptFunction(jsDoc = LEFT_JSDOC) @Override public int getLeft() { return super.getLocation().x; }
public boolean isMouseXOverLabel(Point p) { Point l = totalCount.getLocation(); if (p.x >= l.x && p.x <= (l.x + totalCount.getWidth())) { return true; } return false; } }
@Override public void paint (Graphics g) { super.paint(g); // SKIP g.setColor(palette.getColorForValue(ImportType.SKIP)); int xSkipLoc = skipLabel.getLocation().x + LABEL_CUBE_DISTANCE; int ySkipLoc = skipLabel.getLocation().y; g.fillRect(xSkipLoc, ySkipLoc, COLORCUBE_WIDTH, COLORCUBE_HEIGHT); // IMPORT g.setColor(palette.getColorForValue(ImportType.IMPORT)); int xImportLoc = importLabel.getLocation().x + LABEL_CUBE_DISTANCE; int yImportLoc = importLabel.getLocation().y; g.fillRect(xImportLoc, yImportLoc, COLORCUBE_WIDTH, COLORCUBE_HEIGHT); }
@ScriptFunction(jsDoc = TOP_JSDOC) @Override public int getTop() { return super.getLocation().y; }
public void mouseClicked(MouseEvent ae) { JLabel src = (JLabel) ae.getSource(); src.setLocation(src.getLocation().x + delta_x, src.getLocation().y + delta_y); src.getParent().repaint(); }
public void actionPerformed(ActionEvent e){ label.setLocation(label.getLocation().x, label.getLocation().y+1);
/** * Calculates the locatioin of the context menu. * * @return the upper-left corner location. * @since 3.4.2 */ protected Point calculateContextMenuLocation() { Point location = _label.getLocation(); return new Point(location.x + (_label.getIcon() == null ? 1 : _label.getIcon().getIconWidth() / 2), location.y + _label.getHeight() + 1); }
label.setLocation(label.getLocation().x + me.getX() - pX, label.getLocation().y + me.getY() - pY); jPanel1.revalidate(); jPanel1.repaint();
frame.setVisible(true); System.out.println("lable.location: " + label.getLocation()); System.out.println("label to inner: " + SwingUtilities.convertPoint(label, new Point(0, 0), inner)); System.out.println("label to outter: " + SwingUtilities.convertPoint(label, new Point(0, 0), outter));
int w = img.getWidth(); int h = img.getHeight(); frame.setSize(w, h); // I just did that to make the example easier to understand JLabel label = new JLabel(new ImageIcon(img)); // so your "background" label with the map image // we need this dot label somewhere else and it must be final final JLabel dot = new JLabel(new ImageIcon(redDot)); // and your dot label with the dot image as icon label.add(dot); frame.add(label); label.setBounds(0, 0, w, h); // just for the example, the map-label is set to fill the frame dot.setBounds(50, 50, 60, 60); // setBounds will handle both: location and size frame.pack(); // pack will do all the stuff to make sure everything is painted and has the correct size when the window becomes visible // and here comes the animation: // my solution is to use a swing timer. Swing timers execute in a background thread and are perfectly suited to "update" any swing component without blocking the User Input thread. // this timer will call the actionPerformed() of the ActionListener every 500 ms Timer timer = new Timer(500, new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ Point location = dot.getLocation(); // get current location of the dot dot.setLocation(location.x + 10, location.y + 10); // just set a new location 10 px further right and further down dot.revalidate(); // revalidate, so the updated position will be taken into account when the dot label will get painted again } }); timer.start(); // start the timer and it will immediately start moving your dot on the img
Point point = result.getLocation(); point.x += xDelta; point.y += yDelta;
Point loc = label1.getLocation(); System.out.println(floc); popup1.setLocation((int)(floc.getX()+loc.getX())-20, (int)(floc.getY()+loc.getY())+40); loc = label2.getLocation(); popup2.setLocation((int)(floc.getX()+loc.getX())+20, (int)(floc.getY()+loc.getY())+40);
super.doLayout(); label.setSize(label.getPreferredSize()); label.getLocation(p);