private void addImage(Image img) { // for JDK9; see explanation in PagePane AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform(); label.setSize((int) Math.ceil(img.getWidth(null) / tx.getScaleX()), (int) Math.ceil(img.getHeight(null) / tx.getScaleY())); label.setIcon(new HighResolutionImageIcon(img, label.getWidth(), label.getHeight())); label.revalidate(); }
label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);
@Override protected void done() { try { BufferedImage image = get(); // We cannot use "label.setIcon(new ImageIcon(get()))" here // because of blurry upscaling in JDK9. Instead, the label is now created with // a smaller size than the image to compensate that the // image is scaled up with some screen configurations (e.g. 125% on windows). // See PDFBOX-3665 for more sample code and discussion. label.setSize((int) Math.ceil(image.getWidth() / defaultTransform.getScaleX()), (int) Math.ceil(image.getHeight() / defaultTransform.getScaleY())); label.setIcon(new HighResolutionImageIcon(image, label.getWidth(), label.getHeight())); label.setText(null); } catch (InterruptedException | ExecutionException e) { label.setText(e.getMessage()); throw new RuntimeException(e); } } }
int componentHeight = labelRender.getHeight();
lblTableImage.setSize(new Dimension(lblTableImage.getWidth(), height)); Image tableImage = ImageHelper.getImageFromResources(draftView.getBoosterNum() == 2 ? "/draft/table_left.png" : "/draft/table_right.png"); BufferedImage resizedTable = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(tableImage, BufferedImage.TYPE_INT_ARGB), lblTableImage.getWidth(), lblTableImage.getHeight()); lblTableImage.setIcon(new ImageIcon(resizedTable));
@Override public int getHeight() { int retValue = super.getHeight(); if (painting) { retValue = pHeight; } return retValue; }
@Override public int getHeight() { int retValue = super.getHeight(); if (painting) { retValue = pHeight; } return retValue; }
@Override public int getHeight() { int retValue = super.getHeight(); if (painting) { retValue = pHeight; } return retValue; }
@Override public int getHeight() { int retValue = super.getHeight(); if (painting) { retValue = pHeight; } return retValue; }
public class MyPanel extends JPanel { JLabel label=...; @Override public Dimension getPreferredSize() { return new Dimension(label.getWidth(),label.getHeight()); } }
public void paint(java.awt.Graphics g) { super.paint(g); java.awt.Color og = g.getColor(); g.setColor(inSuspension ? java.awt.Color.red : (suspendExecution ? java.awt.Color.yellow : java.awt.Color.green)); g.fillOval(conl.getWidth() - conl.getHeight() - 3, 3, conl.getHeight() - 6, conl.getHeight() - 6); g.setColor(og); } };
/** * Returns the available height to paint text on. This is the height of the * passed component with insets subtracted. * * @param l * a component * @return the available height */ protected int getAvailableHeight(final JLabel l) { l.getInsets(paintViewInsets); return l.getHeight() - paintViewInsets.top - paintViewInsets.bottom; }
JLabel srcLabel = new JLabel(); JLabel dest = new JLabel(); BufferedImage img = new BufferedImage(srcLabel.getWidth(), srcLabel.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); srcLabel.printAll(g2d); g2d.dispose(); dest.setIcon(new ImageIcon(img));
@Override public void mouseClicked(MouseEvent mouseEvent) { super.mouseClicked(mouseEvent); int x = mouseEvent.getX(); int y = mouseEvent.getY(); try { writer.write("DOWN" + (x * 1.0f / label.getWidth()) + "#" + (y * 1.0f / label.getHeight())); writer.newLine(); writer.write("UP" + (x * 1.0f / label.getWidth()) + "#" + (y * 1.0f / label.getHeight())); writer.newLine(); writer.flush(); } catch (Exception e) { } }
public int getWidth() { if ((painting) && (isRotated())) return super.getHeight(); return super.getWidth(); }
/** * 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); }
private void paintPageIndex() { pageNumber.setText(getPageIndexText()); pageNumber.paintImmediately(0, 0, pageNumber.getWidth(), pageNumber.getHeight()); } }
public boolean intersects(JLabel testa, JLabel testb){ Rectangle rectB = testb.getBounds(); Rectangle result = SwingUtilities.computeIntersection(testa.getX(), testa.getY(), testa.getWidth(), testa.getHeight(), rectB); return (result.getWidth() > 0 && result.getHeight() > 0); }
@Override public void mouseEntered(MouseEvent e) { if (windowInfoLabel.isEnabled()) { richTooltip = buildTooltip(); Point screenLocation = new Point(e.getLocationOnScreen().x, e.getLocationOnScreen().y + windowInfoLabel.getHeight()); richTooltip.showTooltip(windowInfoLabel, screenLocation); } }
private void show(String message) { label.setText(message); JFrame frame = getFrame(); if(frame == null) return; Point locationOnScreen = frame.getLocationOnScreen(); Dimension frameSize = getFrame().getSize(); window.pack(); window.setLocation(locationOnScreen.x + frameSize.width - label.getWidth() - 25, locationOnScreen.y + frameSize.height - label.getHeight() - 25); window.setVisible(true); }