Dialog () { Dialog pickerDialog = getPickerDialog(); if (pickerDialog == null) { pickerDialog = super.getOrCreatePickerDialog(); pickerDialog.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { super.keyPressed(event); int diff = BitUtil.isSet(event.getModifiers(), Event.SHIFT_MASK) ? 10 : 1; Point location = updateLocation(); if (myRobot != null && location != null) { switch (event.getKeyCode()) { case KeyEvent.VK_DOWN -> myRobot.mouseMove(location.x, location.y + diff); case KeyEvent.VK_UP -> myRobot.mouseMove(location.x, location.y - diff); case KeyEvent.VK_LEFT -> myRobot.mouseMove(location.x - diff, location.y); case KeyEvent.VK_RIGHT -> myRobot.mouseMove(location.x + diff, location.y); } updateLocation(); } } }); final JLabel label = new JLabel() { @Override public void paint(Graphics g) { applyRenderingHints(g); Dialog pickerDialog = getPickerDialog(); if (pickerDialog != null && pickerDialog.isShowing()) { Point mouseLoc = updateLocation(); if (mouseLoc == null) return; //final int pixels = UIUtil.isRetina(graphics2d) ? PIXELS / 2 + 1 : PIXELS; int left = PIXELS / 2 + 1; Rectangle captureRectangle = new Rectangle(mouseLoc.x - left, mouseLoc.y - left, PIXELS, PIXELS); BufferedImage captureScreen = captureScreen(pickerDialog, captureRectangle); if (captureScreen == null || captureScreen.getWidth() < PIXELS || captureRectangle.getHeight() < PIXELS) { cancelPipette(); return; } //noinspection UseJBColor Color newColor = new Color(captureScreen.getRGB(captureRectangle.width / 2, captureRectangle.height / 2)); Graphics2D graphics2d = ((Graphics2D)g); Point offset = new Point(10, 10); graphics2d.setComposite(AlphaComposite.Clear); graphics2d.fillRect(0, 0, getWidth(), getHeight()); graphics2d.setComposite(AlphaComposite.Src); graphics2d.clip(new Ellipse2D.Double(offset.x, offset.y, SIZE, SIZE)); graphics2d.drawImage(captureScreen, offset.x, offset.y, SIZE, SIZE, this); // paint magnifier graphics2d.setComposite(AlphaComposite.SrcOver); drawPixelGrid(graphics2d, offset); drawCenterPixel(graphics2d, offset, newColor); drawCurrentColorRectangle(graphics2d, offset, newColor); graphics2d.setClip(0, 0, getWidth(), getHeight()); drawMagnifierBorder(newColor, graphics2d, offset); pickerDialog.repaint(); if (!newColor.equals(getColor())) { setColor(newColor); notifyListener(newColor, 300); } } } }; pickerDialog.add(label); pickerDialog.setSize(DIALOG_SIZE, DIALOG_SIZE); pickerDialog.setBackground(TRANSPARENT_COLOR); BufferedImage emptyImage = UIUtil.createImage(pickerDialog, 1, 1, Transparency.TRANSLUCENT); pickerDialog.setCursor(myParent.getToolkit().createCustomCursor(emptyImage, new Point(0, 0), "ColorPicker")); } return pickerDialog; }