Graphics2d « Graphics « Java Swing Q&A





1. Howto perform a MULTIPLY composite effect using Graphics2D    stackoverflow.com

I have two different javax.swing.Icon objects and I want to a create new Icon which is the composite of these two. I want the composite to be a MULTIPLY effect, similair ...

2. Using Java's Graphics or Graphics2D classes, how do I paint a String?    stackoverflow.com

I have a String and I want to paint it onto an image. I am able to paint points and draw lines, however, even after reading the Text part ...

3. Java - best library to help draw text at arbitrary anchor points    stackoverflow.com

I'm familiar with how to use the various FontMetrics functions to center text vertically, horizontally, and whatnot. However, I am looking for a library that supports drawing text at a ...

4. Multiple Graphics2D Objects    stackoverflow.com

I have a Graphics object of JPanel and that is working fine:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JPanel;

public class GraphicsTest extends JPanel
{
    private Graphics2D g2d;
    private ...

5. Java Graphics2D DrawString    stackoverflow.com

Hey guys I have a little issue here. I have a panel where I am drawing a string. This is a game so I keep redrawing the score in order to ...

6. Is this bad practice? Multiple Graphics2D Objects    stackoverflow.com

I've created a JPanel canvas that holds all graphics; namely JLabel. To get animated sprites to work you have to over ride the paintComponent of the extended JLabel class. I've successfully ...

7. Java - Filling a Custom Shape    stackoverflow.com

I have created a custom shape, essentially it is a collection of four Arc2D objects. When these arcs are drawn they form what could be considered a four point rounded star shape, ...

8. Java Rotating BufferedImages    stackoverflow.com

I am having trouble getting a rotated BufferedImage to display. I think the rotation is working just fine, but I can't actually draw it to the screen. My code:

Class extends JPanel ...

9. Java graphics repaint problem    stackoverflow.com

Having trouble with a simple paint pad in java. Issues with getting my clear button to repaint. The array is clearing but not repainting. Can anyone spot my problem or is ...





10. java gui graphics problem    stackoverflow.com

what i'm trying to do is everytime i click, a square should come up in the Jpanel, but for some reason the Jpanel is blocking the squares(click on the edges). I'm ...

11. Is there a way to get the coordinates for an oval drawn with Graphics2D?    stackoverflow.com

I know the parametric equations to 'hand draw' a circle. I would like to know if there's a quick way to get the coordinates, cuz that would be dope. Yay for ...

12. Painting in a bufferedimage inside swing (Java)    stackoverflow.com

Hey, Im working on a paint application written in java and running into a few (more) problems. I have a gui and a working program(kinda), my only problem is that the ...

13. Reset Graphics2D object in Java    stackoverflow.com

I was experimenting with Graphics2D in Java. But as usual, I am stuck. :P The problem is: Suppose i have this code,

Graphics2D g=(Graphics2D)(this.getGraphics()); //Inside a JFrame
g.rotate(Math.PI/8);
g.drawLine(10, 20, 65, 80);

//I want this one ...

14. Coordinate transformation Dilemma, User coordinate to Device coordinate?    stackoverflow.com

I am working on a task which includes data such as "length" of a road in "millimetre". And as per the specification my JFrame should be 4meter * 3meter ( How ...

15. Issues Creating a Pen Tool with Java's Path2D    stackoverflow.com

I've been attempting to create a pen tool for my Java drawing program using the Path2D class in conjunction with mouse listeners, but I've had baffling results. The tool will work ...

16. Repainting in Swing JComponent after an interval    stackoverflow.com

I have been assigned a project where I have to make an analog clock using the GregorianCalendar object in java. First, we were told to get the clock working, so ...





17. Rotate a Java Graphics2D Rectangle?    stackoverflow.com

I have searched everywhere and I just cant find the answer. How do I rotate a Rectangle in java? Here is some of my code:

package net.chrypthic.Space;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Space ...

18. Java Painting a Triangle and Trying to use other Swing Objects    stackoverflow.com

I am having a bit of an issue using Netbeans to design a GUI (Yeah im lazy :\ ) and manually trying to paint a triangle onto the JFrame. The Swing ...

19. Making margins smaller - Java Printing    stackoverflow.com

I am using this code to print on paper:

//Overriden from printable interface
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
            throws ...

20. Polygon crossed by line    stackoverflow.com

I have polygon and a line.

g.drawLine(this.getLine().getP1().getX(), this.getLine().getP1().getY(),
                this.getLine().getP2().getX(), this.getLine().getP2().getY());

g.drawPolygon(this.polygon);
and I have to find the cross-points between ...

21. why is it only painting one of the components?    stackoverflow.com

package puzzle;

import java.awt.Color;
import javax.swing.*;
import java.util.*;


public class Puzzle {

Integer x = 50;
Integer y = 50;
int x2 = 100;
int y2 = 100;
int vnotx = 0;
int vnoty = 0;
float t = 0;
float t2  ...

22. Swing HTML drawString    stackoverflow.com

I'm trying to create some special component for a specific purpose, on that component I need to draw a HTML string, here's a sample code:

 public class MyComponent extends JComponent{
  ...

23. Java graphics trouble    stackoverflow.com

I have a JComponent with a listener on it. On the JComponent, I draw a big image and the mouse listener adds small images where clicks occur (one big map on ...

24. drawLine doesn't draw line over BufferedImage    stackoverflow.com

I've got a following problem. I want to draw lines over BufferedImage, but they don't show up. If i don't load the image, they will show. What is the problem? Here ...

25. Java: How to deal with graphics?    stackoverflow.com

I am developing a small desktop application in Java using NetBeans. Since i am new to java so i mostly drag and drop controls and work with them. What i have ...

26. Graph using Swing without external library    stackoverflow.com

How to draw (x,y) based graph (line through those points) in Java Swing? I can not use any external library.

27. Java2D/Swing: Rendering a component with text anti aliasing to a BufferedImage    stackoverflow.com

I would like to render a Java Swing component, e.g. a JButton, which I also put on a JFrame, to a BufferedImage. This works in general, but with a major drawback: ...

28. JComponent size issue    stackoverflow.com

I have a JComponent subclass that I am using to draw shapes onto my screen. In the constructor, I am trying to set ballX and ballY to half of the X ...

29. Scaling Graphics2D object shifts it    stackoverflow.com

I have a JScrollPane that contains a custom JLabel with an ImageIcon. I want the user to be able to zoom in and out on the image. I'm trying to use ...

30. Graphics2D using constructor    stackoverflow.com

I want to draw a straight line in JFrame using Line2D.Double, also I want do it with constructor (not through method). How I must declare variable g like in example on ...

31. How to create a rectangle in a rectangle?    stackoverflow.com

In my paintComponent, I have drawRect, which draws a single rectangle. However, I want to make the outline of the rectangle thicker but I don't know how. So I thought of ...

32. Graphics2D and JComponent    stackoverflow.com

I have not used Swing/G2D much, so please be patient. I have the following class which is a component on my GUI (meant to be a kind of Canvas to draw on):

import ...

33. Graphics2D - Rotating Shapes on a Graphics2D object    stackoverflow.com

I have a Graphics2D object which I use to draw on my Canvas. I draw multiple shapes on the Canvas and want to transform only one (or part) of them. I'll try ...

34. How do I set the size of a printed page in java?    stackoverflow.com

I have written a program that uses the Java print API to print pages from a printer. I believe I have put in code to set the page size to letter, ...

35. Java - swing - Graphics2D - how to visualize math functions    stackoverflow.com

I've just faced an interesting thing as Math functions but as I can get it Math may contain float function values but Graphics2D can be used to paint just N values ...

36. Graphics2D    coderanch.com

Hi pankaj, the other option you have is to redraw the same line before applying a new affine transform. this should be easy if you have just a single line. it will also improve the performance since only a very small area is affected. also, you can avoid the for loop by using the timer class to generate repaint events for ...

37. Graphics2D problem    coderanch.com

I create an Image using JAVA Graphics2D API. The code is running well in Windows. But I got the following error in UNIX server. It seems that it has trouble with X11 window. Anybody knows how to solve this problem? Thanks in advance! jenny Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable. java.lang.InternalError: Can't ...

38. Graphics2D questions    coderanch.com

Ok, I have 2 questions. The first, and more urgent of the two, is: is it possible to draw transparency onto a graphics object? Like setting the color to a transparent value and then proceeding to draw with that value as you would with a normal color. The second is: is it possible to compare colors? For instance: Color colorA = ...

39. Is there a getPoints for a Graphics or Graphics2D object    coderanch.com

How can retrieve an array of points for a particular Graphics object. I want to be able to do a free hand drawing (of a Region Of Interest) and store that ROI into a database. So I was hoping to be able to access the data from the database either in object form or as a list of x and y ...

40. Printing: How to disable doubleBuffering on Graphics2D?    coderanch.com

Hello all, I want to print a JPanel jp1 and some graphics (rectangle, rectangle2D and drawn Strings) on the same paper. For some special reasons I cannot add the graphics and the panel jp1 to another JPanel and print this other panel on my printer. So I need to create a printerJob() for my JPanel jp1 and draw the graphics on ...

41. Graphics2D    coderanch.com

42. Graphics2D    coderanch.com

Hi I want to have something like a speedometer. I draw it with Java2D Graphics2D g2d = ( Graphics2D ) new Graphics; GeneralPath filledPolygon = new GeneralPath(); filledPolygon.moveTo( x, yo1 ); filledPolygon.lineTo( x, yu1 ); filledPolygon.lineTo( x1, yu1 ); filledPolygon.lineTo( x1, yu2 ); filledPolygon.lineTo( x2, y ); filledPolygon.lineTo( x1, yo2 ); filledPolygon.lineTo( x1, yo1 ); filledPolygon.lineTo( x, yo1 ); AffineTransform af ...

43. Graphics2D compiler error    coderanch.com

I'm studying up on the Printable interface and am trying to use an example from a book. I'm getting compile errors on the variable g2, (Marked in code). Since class Graphics2D is abstract and I'm subclassing from parent Graphics g, I don't understand what the compiler wants. This is just part of the code containing the class. Thanks... PrinterClass.java:187: cannot resolve ...

44. Graphics2D    coderanch.com

45. Graphics2D ??? help    coderanch.com

Hi! I have some principal question to this Graphics2D class: It seems, that the use of this class transforms my drawing in some way. Could this be possible? I was reading a little around in the API-documentation and there was something about this AffineTransform class and that my Graphcis2D context uses a default instance of that. I would like to draw ...

46. problem with Graphics2D.rotate()    coderanch.com

We have an image that we print out on 4 x 6 inch sticky labels (with a thermal printer). Now we can also print on some that are approximately 4 x 8 inches, but because there's a peel-off tab on one end, we're adding a bit of info to the label, and we need to send the image to the printer ...

47. raphics &graphics2d    coderanch.com

48. way to rotate without using Graphics2D.rotate()    coderanch.com

I've had lots of issues with using rotate and then translate to get an image rotated 180 degrees the way I want to. My problem is that I need the image to be generated upside down now, and I'm rotating it Math.PI and then translating it back into place, but I can't get it right (in trying to translate it to ...

49. Graphics2D drawOval(int,int,int,int) method    coderanch.com

Hi there. I am trying to draw a simple circle/oval to reperesent how a point object, e.g. shop, appears in a map legend. I am adding the object to a JPanel upon which the map legend has been created. The problem is that I am having real difficulty determining what int parameters to assign in order to draw the best possible ...

50. bufferedImage and Graphics2D    coderanch.com

Im writing a class which intends to turn a bufferedimage objects into a graphics2d object so as to make use of the draw() method. Once that's done the method will return the graphics object to the class subclassing a JFrame. This class will position and paint the graphics object onto the JPanel. At least thats the intention but: I'm stuck painting ...

51. How specify to graphics2d which colors should be of what alpha level?    coderanch.com

I have an image where i want to allow someone to pick which colors are of custom alpha level. So for example, they could click on pixel (x=5, y=23) which, let's say is Color(245,123,119). Then they say, that color is alpha 0.4. So everywhere in the image where that pixel appears, the graphics object will paint it with an alpha level ...

52. How to Create a Graphics2D object.    coderanch.com

Lisa, There's a fundamental problem in what you're trying to do: Graphics (or Graphics2D) objects cannot be created from scratch - they are only meaningful as the drawing context for a destination "surface" (either a component or an image). How you get the Graphics object you want depends on what you want to do. If you want to draw to an ...

53. Subclassing Graphics2D    coderanch.com

One article that I read about testing GUI intensive applications suggested subclassing the Graphics object to provide a textual representation of the calls made on it (http://c2.com/cgi/wiki?ExtremeProgrammingTestingGuiIntensiveApps) my question is, since the Graphics object is propagated by the Swing components that control the rendering of individual controls, how can one substitute a subclass in a coherent manner. One solution I can ...

54. Issues with Graphics2D drawString method    coderanch.com

I has a image file on which i need to write user defined text. I am able to save the image with text written on it to a image file but when same output stream is directed to Jsp for displaying to user on fly the g.drawString text is visible but when saved to local machine as .jpg file the text ...

55. Issue with graphics2d    coderanch.com

57. Drawing text inside a Graphics2D shape    coderanch.com

My application allows the user to draw shapes. Say I've got a rectangle (subclass of Rectangle2D.Double) drawn, now I want to allow the user to double click on the rectangle and a text field with flashing cursor should appear. The user can type in the desired text and pressed enter or click outside the shape to stop editing text. The text ...

58. Is there a better way to blend colors when painting with Graphics2D?    coderanch.com

I've recently been using Java to produce some simple anaglyph 3-D images -- "anaglyph" being the type of 3-D where you paint images for the left eye in one color (typically red) and for the right eye in another color (typically cyan) so, if you put on a pair of goofy looking 3-D glasses and look at the combined results, a ...

59. Problem with graphics2d and JLable while overloading paintComponent() method    coderanch.com

Hello i have a problem at extending a JLabel. What i want to do is to extend a jlabel to look like a 3d component. That is why i extend the jlabel and overload the method paintComponent(). To get into the problem i will list the code so someone can help. Thank you in advance. Here is the code: /* * ...

60. Swing's components and Graphics2D.scale    coderanch.com

Hello, I have image and Swing components in my panel and I'm trying to resizing it by using Graphics2D.scale(int, int), but Swing's component aren't looking properly after that. See what's happen with JButton and JLabel after using Graphics2D.scale. How can I fix it? import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class Test{ public ...

61. Graphics2D + Java Swing    forums.oracle.com

Hello, I am having difficulty in displaying graphics2d(bufferedImage) with Java Swing - The Swing does not show, unless it is a button and you move your mouse over it. The problem disappears when the "public void paint(Graphics g) {.." is employed. Can anyone suggest an article to read about solving this? regards david55

62. Adding Graphics2D to swing    forums.oracle.com

Hi, I have a few classes / threads that take and write to a graphics2d object. I want to be able to stick a graphics2d object in a swing gui then pass it to these objects and let them do their work. However, everything I find doesn't say I can't do it, but goes about doing all the work in one ...