javax.swing.JComponent.getGraphics()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中javax.swing.JComponent.getGraphics()方法的一些代码示例,展示了JComponent.getGraphics()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.getGraphics()方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:getGraphics

JComponent.getGraphics介绍

暂无

代码示例

代码示例来源:origin: geotools/geotools

/** Creates and initializes the graphics object if required. */
  private void ensureGraphics() {
    if (graphics == null) {
      graphics = (Graphics2D) parentComponent.getGraphics().create();
      graphics.setColor(Color.WHITE);
      graphics.setXORMode(Color.RED);
    }
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void setFont(Font font) {
 super.setFont(font);
 Graphics g = this.getGraphics();
 if (g != null) {
  FontMetrics fm = g.getFontMetrics(font);
  int height = fm.getHeight();
  _rowHeight = height + height / 3;
  setRowHeight(_rowHeight);
 }
}

代码示例来源:origin: stackoverflow.com

update(getGraphics());

代码示例来源:origin: apache-log4j/log4j

public void setFont(Font font) {
 super.setFont(font);
 Graphics g = this.getGraphics();
 if (g != null) {
  FontMetrics fm = g.getFontMetrics(font);
  int height = fm.getHeight();
  _rowHeight = height + height / 3;
  setRowHeight(_rowHeight);
 }
}

代码示例来源:origin: org.geotools/gt-swing

/**
 * Creates and initializes the graphics object if required.
 */
private void ensureGraphics() {
  if (graphics == null) {
    graphics = (Graphics2D) parentComponent.getGraphics().create();
    graphics.setColor(Color.WHITE);
    graphics.setXORMode(Color.RED);
  }
}

代码示例来源:origin: org.apache.log4j/com.springsource.org.apache.log4j

public void setFont(Font font) {
 super.setFont(font);
 Graphics g = this.getGraphics();
 if (g != null) {
  FontMetrics fm = g.getFontMetrics(font);
  int height = fm.getHeight();
  _rowHeight = height + height / 3;
  setRowHeight(_rowHeight);
 }
}

代码示例来源:origin: org.jboss.logmanager/log4j-jboss-logmanager

public void setFont(Font font) {
 super.setFont(font);
 Graphics g = this.getGraphics();
 if (g != null) {
  FontMetrics fm = g.getFontMetrics(font);
  int height = fm.getHeight();
  _rowHeight = height + height / 3;
  setRowHeight(_rowHeight);
 }
}

代码示例来源:origin: de.sciss/prefuse-core

/**
 * Check if any label text is obscured.
 */
private static boolean isTextObscured(JComponent c, String s) {
  Graphics g = c.getGraphics();
  FontMetrics fm = g.getFontMetrics(c.getFont());
  int sw = fm.stringWidth(s);
  return ( sw > c.getWidth() );
}

代码示例来源:origin: org.apache/log4j

public void setFont(Font font) {
 super.setFont(font);
 Graphics g = this.getGraphics();
 if (g != null) {
  FontMetrics fm = g.getFontMetrics(font);
  int height = fm.getHeight();
  _rowHeight = height + height / 3;
  setRowHeight(_rowHeight);
 }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.log4j

public void setFont(Font font) {
 super.setFont(font);
 Graphics g = this.getGraphics();
 if (g != null) {
  FontMetrics fm = g.getFontMetrics(font);
  int height = fm.getHeight();
  _rowHeight = height + height / 3;
  setRowHeight(_rowHeight);
 }
}

代码示例来源:origin: klamonte/jexer

/**
 * Creates a graphics context for this component. This method will return
 * null if this component is currently not displayable.
 *
 * @return a graphics context for this component, or null if it has none
 */
public Graphics getGraphics() {
  if (frame != null) {
    return frame.getGraphics();
  } else {
    return component.getGraphics();
  }
}

代码示例来源:origin: dhale/jtk

private void drawRect(JComponent c, int x, int y, boolean bx, boolean by) {
  _xdraw = x;
  _ydraw = y;
  int xmin = bx?min(_xbegin,_xdraw):-1;
  int xmax = bx?max(_xbegin,_xdraw):c.getWidth();
  int ymin = by?min(_ybegin,_ydraw):-1;
  int ymax = by?max(_ybegin,_ydraw):c.getHeight();
  Graphics g = c.getGraphics();
  g.setColor(Color.RED);
  g.setXORMode(c.getBackground());
  g.drawRect(xmin,ymin,xmax-xmin,ymax-ymin);
  g.dispose();
 }
}

代码示例来源:origin: net.sf.tinylaf/tinylaf

public void mousePressed(MouseEvent e) {
  if(e.getX() < 1 || e.getX() > 256) return;
  if(e.getY() < 1 || e.getY() > 256) return;
  
  s = e.getX() - 1;
  if(s < 0) s = 0;
  else if(s > 255) s = 255;
  
  int y = e.getY() - 1;
  if(y < 0) y = 0;
  else if(y > 255) y = 255;
  
  mousePressed = true;
  
  b = 255 - y;
  paint(ColorSelector.this.getGraphics());
  theColor = Color.getHSBColor(hue, (float)(s / 255.0), (float)(b / 255.0));				
  colorChanged(theColor);
}

代码示例来源:origin: net.sf.tinylaf/tinylaf

public void mouseDragged(MouseEvent e) {
    s = e.getX() - 1;
    if(s < 0) s = 0;
    else if(s > 255) s = 255;
    
    int y = e.getY() - 1;
    if(y < 0) y = 0;
    else if(y > 255) y = 255;
    
    b = 255 - y;
    paint(ColorSelector.this.getGraphics());
    theColor = Color.getHSBColor(hue, (float)(s / 255.0), (float)(b / 255.0));				
    colorChanged(theColor);
  }
}

代码示例来源:origin: net.sf.jt400/jt400

/**
Clears the current view.
**/
  synchronized public void clearView()
  {
    Rectangle r = getVisibleRect();
    getGraphics().clearRect(r.x, r.y, r.width, r.height);
  }

代码示例来源:origin: de.rototor.jeuclid/jeuclid-core

/**
 * Retrieve the preferred size of the math component.
 * 
 * @param c
 *            the math component to measure
 * @return the preferred size.
 */
private Dimension getMathComponentSize(final JComponent c) {
  JEuclidView jEuclidView = this.getJeuclidView(c.getGraphics(), c);
  return this.calculatePreferredSize(c, jEuclidView);
}

代码示例来源:origin: org.openspml/openspml

/**
 * Get the effective Graphics object for a component.
 */
public static Graphics getGraphics(JComponent comp) {
Graphics g = comp.getGraphics();
if (g == null) {
  JFrame frame = getParentFrame(comp);
  if (frame != null)
  g = frame.getGraphics();
}
return g;
}

代码示例来源:origin: com.googlecode.obvious/obvious-ivtk

/**
 * Zooms the view to the given scale.
 * @param p anchor point for the zoom
 * @param scale scale for the zoom
 */
public void zoom(Point2D p, float scale) {
 Graphics2D g = ((Graphics2D) this.getViewJComponent().getGraphics());
 double x = p.getX(), y = p.getY();
 this.trsf.translate(x, y);
 this.trsf.scale(scale, scale);
 this.trsf.translate(-x, -y);
 g.clearRect(0, 0, getViewJComponent().getSize().width,
   getViewJComponent().getSize().height);
 g.setTransform(trsf);
 this.customPanel.setScaleValue(scale);
 this.customPanel.setPanValues(x, y);
 this.paint(g);
}

代码示例来源:origin: com.googlecode.obvious/obvious-ivtk

/**
 * Pans the view provided in screen coordinates.
 * @param indx the amount to pan along the x-dimension, in pixel units
 * @param indy the amount to pan along the y-dimension, in pixel units
 */
public void pan(float indx, float indy) {
 this.trsf.translate(indx, indy);
 Graphics2D g = ((Graphics2D) this.getViewJComponent().getGraphics());
 g.clearRect(0, 0, getViewJComponent().getSize().width,
   getViewJComponent().getSize().height);
 g.setTransform(trsf);
 Rectangle2D bounds = new Rectangle2D.Float(
   0, 0, getViewJComponent().getWidth() + indx,
   getViewJComponent().getHeight() + indy);
 this.customPanel.setBounds(bounds);
 this.customPanel.setPanValues((double) indx,  (double) indy);
 this.paint(g);
}

代码示例来源:origin: nroduit/Weasis

@Override
public void setLabel(ViewCanvas<?> view2d, Double xPos, Double yPos, String... labels) {
  if (labels == null || labels.length == 0) {
    reset();
  } else {
    this.labels = labels;
    Font defaultFont = view2d == null ? FontTools.getFont12() : view2d.getFont();
    Graphics2D g2d = view2d == null ? null : (Graphics2D) view2d.getJComponent().getGraphics();
    FontRenderContext fontRenderContext =
      g2d == null ? new FontRenderContext(null, false, false) : g2d.getFontRenderContext();
    updateBoundsSize(defaultFont, fontRenderContext);
    labelBounds = new Rectangle.Double(xPos + GROWING_BOUND, yPos + GROWING_BOUND, labelWidth + GROWING_BOUND,
      (labelHeight * labels.length) + GROWING_BOUND);
    GeomUtil.growRectangle(labelBounds, GROWING_BOUND);
  }
}

相关文章

JComponent类方法