Tabnine Logo
Graphics.create
Code IndexAdd Tabnine to your IDE (free)

How to use
create
method
in
java.awt.Graphics

Best Java code snippets using java.awt.Graphics.create (Showing top 20 results out of 1,791)

Refine searchRefine arrow

  • JFrame.setDefaultCloseOperation
  • JFrame.<init>
  • Window.setVisible
  • Container.add
  • Graphics.dispose
  • Dimension.<init>
origin: stackoverflow.com

    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new TestPane());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  return new Dimension(200, 200);
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.dispose();
origin: stackoverflow.com

  JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new DropPane());
return new Dimension(400, 400);
super.paintComponent(g);
if (dragOver) {
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.setColor(new Color(0, 255, 0, 64));
  g2d.fill(new Rectangle(getWidth(), getHeight()));
origin: stackoverflow.com

JFrame f = new JFrame();
f.add(new JComponent() {
    Graphics2D g = (Graphics2D) g1.create();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 400);
f.setVisible(true);
origin: stackoverflow.com

JFrame t = new JFrame();
t.add(new JComponent() {
    Graphics2D g = (Graphics2D) g1.create();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setSize(400, 400);
t.setVisible(true);
origin: stackoverflow.com

    JFrame frame = new JFrame("Spot");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    Balls balls = new Balls();
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  for (Ball ball : ballsUp) {
  size = new Dimension(30, 30);
origin: stackoverflow.com

 public static void main(String[] args) throws Exception {

  JFrame frame = new JFrame("Test");

  frame.add(new JComponent() {
    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);

      Graphics2D g2 = (Graphics2D) g.create();
      {
        g2.translate(0, getHeight() - 1);
        g2.scale(1, -1);

        g2.drawLine(0, 0, 100, 100);
      }
      g2.dispose();
    }
  });

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(400, 300);
  frame.setVisible(true);
}
origin: stackoverflow.com

  Graphics2D g2d = (Graphics2D) g.create();
  g2d.setColor(new Color(0xFFAA00));
  g2d.dispose();
  add(usrNameLabel, labCnst);
  add(usrNameFeild, txtCnst);
  add(passwordLabel, labCnst);
  add(passFeild, txtCnst);
   super.paint(g); //To change body of generated methods, choose Tools | Templates.
  Graphics2D g2d = (Graphics2D)g.create(); // cloning to work, it is safer aproach
  Rectangle2D txRect = new Rectangle2D.Double(0, 0, textureImg.getWidth(), textureImg.getHeight());
  TexturePaint txPaint = new TexturePaint(textureImg, txRect);
  g2d.dispose();// disposing the graphics object 
protected void paintComponent(Graphics g) {
  super.paintComponent(g); //To change body of generated methods, choose Tools | Templates.
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.dispose();
      JFrame frame = new JFrame("Demo: LogIn Dialogue");
origin: stackoverflow.com

  JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new ShapedPane());
return new Dimension(200, 200);
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.BLACK);
origin: stackoverflow.com

 JFrame f=new JFrame("Disabling via JLayer");
final JLayer<JTree> layer = new JLayer<JTree>(new JTree(), new LayerUI<JTree>() {
 @Override
 public void eventDispatched(AWTEvent e, JLayer<? extends JTree> l) {
  if(e instanceof InputEvent) ((InputEvent)e).consume();
 }
 @Override
 public void paint(Graphics g, JComponent c) {
  super.paint(g, c);
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
  g2d.setColor(Color.BLACK);
  g2d.fillRect(0, 0, c.getWidth(), c.getHeight());
  g2d.dispose();
 }
});
f.setContentPane(layer);
layer.setLayerEventMask(~0);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
origin: stackoverflow.com

JFrame f = new JFrame();
Test t = new Test();
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(t,BorderLayout.CENTER);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
setPreferredSize(new Dimension(300, 300));
Graphics2D g2 = (Graphics2D)g.create();
Rectangle2D rectangleNotToDrawIn = new Rectangle2D.Double(100, 100, 20, 30);
Area outside = calculateRectOutside(rectangleNotToDrawIn);
origin: stackoverflow.com

    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new ScalePane());
  try {
    original = ImageIO.read(new File("path/to/master.jpg"));
    scaled = getScaledInstanceToFit(original, new Dimension(60, 60));
    ImageIO.write(scaled, "jpg", new File("scaled.jpg"));
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    int imageWidth = img.getWidth();
    int imageHeight = img.getHeight();
    scale = getScaleFactorToFit(new Dimension(imageWidth, imageHeight), size);
origin: stackoverflow.com

    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new TestPane());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  return new Dimension(200, 200);
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.drawString(text, x, y);
  g2d.dispose();
origin: stackoverflow.com

  JFrame frame = new JFrame("Test");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new TestPane());
return new Dimension(200, 200);
int height = getHeight() - 1;
Graphics2D g2d = (Graphics2D) g.create();
applyQualityProperties(g2d);
Insets insets = getInsets();
origin: stackoverflow.com

final JFrame frame = new JFrame("Gradient JButton Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new FlowLayout());
frame.add(JGradientButton.newInstance());
frame.setSize(new Dimension(300, 150)); // used for demonstration
frame.setVisible(true);
  final Graphics2D g2 = (Graphics2D) g.create();
  g2.setPaint(new GradientPaint(
      new Point(0, 0), 
      Color.PINK.darker()));
  g2.fillRect(0, 0, getWidth(), getHeight());
  g2.dispose();
origin: stackoverflow.com

final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        return new Dimension(200, 200);
        Graphics g2 = g.create();
        g2.dispose();
origin: stackoverflow.com

Graphics2D g2d = (Graphics2D)g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.DARK_GRAY);
g2d.setColor(Color.WHITE);
g2d.drawString("Loading image...", getWidth()/2 - 45, getHeight()/2 + 3 );
g2d.dispose();
  public void run() {
    final MyCanvas canvas = new MyCanvas();
    JFrame frame = new JFrame();
   frame.setSize(new Dimension(500, 500));
   frame.add(canvas);
   frame.setVisible(true);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
origin: stackoverflow.com

GlyphVector v = f.createGlyphVector(getFontMetrics(f).getFontRenderContext(), "Hello");
s = v.getOutline();
setPreferredSize(new Dimension(300,300));
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.translate(100, 150);
JFrame f = new JFrame("Test");
Component c = new Test();
f.getContentPane().add(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
origin: stackoverflow.com

 @Override
 public void run() {
  JFrame frame = new JFrame( "RotatingIcon" );
  JTabbedPane tabbedPane = new JTabbedPane(  );
  tabbedPane.addTab( "Searching", new RotatingIcon( new ImageIcon( "resources/images/progress-indeterminate.png" ), tabbedPane ),
            new JLabel( new ImageIcon( "resources/images/rotatingIcon.gif" ) ) );
  frame.getContentPane().add( tabbedPane );
  frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  frame.pack();
  frame.setVisible( true );
public void paintIcon( Component c, Graphics g, int x, int y ) {
 rotatingTimer.stop();
 Graphics2D g2 = (Graphics2D )g.create();
 int cWidth = delegateIcon.getIconWidth() / 2;
 int cHeight = delegateIcon.getIconHeight() / 2;
origin: stackoverflow.com

    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new TestPane());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  return new Dimension(200, 200);
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.draw(bounds);
  g2d.dispose();
origin: stackoverflow.com

  JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new JScrollPane(new TestPane()));
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
Dimension size = new Dimension(200, 200);
if (img != null) {            
  size.width = Math.round(img.getWidth() * scale);
super.paintComponent(g);
if (img != null) {
  Graphics2D g2d = (Graphics2D) g.create();
  AffineTransform at = new AffineTransform();
  at.scale(scale, scale);
  g2d.drawImage(img, at, this);
  g2d.dispose();
java.awtGraphicscreate

Javadoc

Creates a new Graphics object based on this Graphics object, but with a new translation and clip area. The new Graphics object has its origin translated to the specified point (x, y). Its clip area is determined by the intersection of the original clip area with the specified rectangle. The arguments are all interpreted in the coordinate system of the original Graphics object. The new graphics context is identical to the original, except in two respects:

  • The new graphics context is translated by (x, y). That is to say, the point (0, 0) in the new graphics context is the same as (x, y) in the original graphics context.
  • The new graphics context has an additional clipping rectangle, in addition to whatever (translated) clipping rectangle it inherited from the original graphics context. The origin of the new clipping rectangle is at (0, 0), and its size is specified by the width and height arguments.

Popular methods of Graphics

  • setColor
  • drawImage
    Draws as much of the specified image as is currently available. The image is drawn with its top-left
  • fillRect
    Fills the specified rectangle. The left and right edges of the rectangle are atx and x + width - 1.
  • drawLine
    Draws a line, using the current color, between the points(x1, y1) and (x2, y2) in this graphics con
  • drawString
    Draws the text given by the specified iterator, using this graphics context's current color. The ite
  • dispose
    Disposes of this graphics context and releases any system resources that it is using. A Graphics obj
  • setFont
    Sets this graphics context's font to the specified font. All subsequent text operations using this g
  • drawRect
    Draws the outline of the specified rectangle. The left and right edges of the rectangle are atx and
  • getFontMetrics
  • getColor
    Gets this graphics context's current color.
  • translate
    Translates the origin of the graphics context to the point (x,y) in the current coordinate system. M
  • getClipBounds
    Returns the bounding rectangle of the current clipping area. The coordinates in the rectangle are re
  • translate,
  • getClipBounds,
  • setClip,
  • getFont,
  • fillPolygon,
  • fillOval,
  • drawOval,
  • getClip,
  • drawRoundRect

Popular in Java

  • Reactive rest calls using spring rest template
  • putExtra (Intent)
  • startActivity (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now