List of usage examples for javax.swing JComponent getHeight
@BeanProperty(bound = false) public int getHeight()
From source file:Main.java
public static void setWidth(JComponent component, int width) { component.setSize(new Dimension(width, component.getHeight())); }
From source file:Utils.java
/** * Renders a component into an image, which is useful for playing with the component's * resultant image in special effects or transitions * * @param component The component to render * @return A buffered image with the rendered component. *///ww w. j av a 2s. c om public static BufferedImage renderComponentToImage(JComponent component) { //Create the image BufferedImage image = createCompatibleImage(component.getWidth(), component.getHeight()); //Render the component onto the image Graphics graphics = image.createGraphics(); // component.update(graphics); component.paint(graphics); graphics.dispose(); return image; }
From source file:Main.java
/** * Sets where a component should be painted. It uses the * {@code JComponent}'s width and height and excludes the {@code Insets}. * /*from ww w .j av a 2 s.co m*/ * @param c the component * @param viewRect the bounds for painting the component */ public static void setViewBounds(JComponent c, Rectangle viewRect) { Insets i = c.getInsets(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = c.getWidth() - (i.right + viewRect.x); viewRect.height = c.getHeight() - (i.bottom + viewRect.y); }
From source file:PaintUtils.java
/** * Paints a top to bottom gradient fill over the component bounds * from color1 to color2.//from www . j a v a 2 s .c o m */ public static void paintGradient(Graphics g, JComponent comp, Color color1, Color color2) { GradientPaint paint = new GradientPaint(0, 0, color1, 0, comp.getHeight(), color2, true); Graphics2D g2 = (Graphics2D) g; Paint oldPaint = g2.getPaint(); g2.setPaint(paint); g2.fillRect(0, 0, comp.getWidth(), comp.getHeight()); g2.setPaint(oldPaint); }
From source file:Myopia.java
@Override public void paint(Graphics g, JComponent c) { int w = c.getWidth(); int h = c.getHeight(); if (w == 0 || h == 0) { return;/* ww w.j a v a 2 s . c om*/ } // Only create the offscreen image if the one we have // is the wrong size. if (mOffscreenImage == null || mOffscreenImage.getWidth() != w || mOffscreenImage.getHeight() != h) { mOffscreenImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); } Graphics2D ig2 = mOffscreenImage.createGraphics(); ig2.setClip(g.getClip()); super.paint(ig2, c); ig2.dispose(); Graphics2D g2 = (Graphics2D) g; g2.drawImage(mOffscreenImage, mOperation, 0, 0); }
From source file:probe.com.model.util.SwingToImageGenerator.java
public String generateHeatMap(JComponent component) { BufferedImage heatMapImg = new BufferedImage((component.getWidth()), (component.getHeight()), BufferedImage.TYPE_INT_ARGB); Graphics g = heatMapImg.getGraphics(); component.paint(g);//from www . j ava 2 s .c o m return generateEncodedImg(heatMapImg); }
From source file:org.jfree.graphics2d.demo.SwingUIToSVGDemo.java
@Override public void actionPerformed(ActionEvent e) { JComponent c = (JComponent) getContentPane().getComponent(0); SVGGraphics2D g2 = new SVGGraphics2D(c.getWidth(), c.getHeight()); c.paint(g2);//from w w w .java 2s .com File f = new File("SwingUIToSVGDemo.svg"); try { SVGUtils.writeToSVG(f, g2.getSVGElement()); } catch (IOException ex) { System.err.println(ex); } }
From source file:Wallpaper.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); Graphics2D g2 = (Graphics2D) g.create(); int w = c.getWidth(); int h = c.getHeight(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); g2.setPaint(new GradientPaint(0, 0, Color.yellow, 0, h, Color.red)); g2.fillRect(0, 0, w, h);/*from www. j av a 2 s. c om*/ g2.dispose(); }
From source file:TapTapTap.java
@Override public void paint(Graphics g, JComponent c) { int w = c.getWidth(); int h = c.getHeight(); // Paint the view. super.paint(g, c); if (!mIsRunning) { return;/*from w w w .j a va 2 s . c o m*/ } Graphics2D g2 = (Graphics2D) g.create(); float fade = (float) mFadeCount / (float) mFadeLimit; // Gray it out. Composite urComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade)); g2.fillRect(0, 0, w, h); g2.setComposite(urComposite); // Paint the wait indicator. int s = Math.min(w, h) / 5; int cx = w / 2; int cy = h / 2; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g2.setPaint(Color.white); g2.rotate(Math.PI * mAngle / 180, cx, cy); for (int i = 0; i < 12; i++) { float scale = (11.0f - (float) i) / 11.0f; g2.drawLine(cx + s, cy, cx + s * 2, cy); g2.rotate(-Math.PI / 6, cx, cy); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade)); } g2.dispose(); }
From source file:LayeredPaneDemo.java
public void paint(Graphics g, JComponent c) { super.paint(g, c); if (c.getBorder() != null) c.getBorder().paintBorder(c, g, 0, 0, c.getWidth(), c.getHeight()); }