java-2d

[Java] How can I cut an image using a color pattern?

Hi there, my name is Daniel and I'm from Spain. I am developing a small program which cuts images by the color. That's will be easiest to explain using an example image. I have got this image: http://dl.dropbox.com/u/944667/Ejemplo1.png And I want to create a new image just with the purple form, without the black frame. Does anyone ...

improving drawing pythagoras tree

Hello. I have written program for drawing pythagoras tree fractal. Can anybody see any way of improving it ? Now it is 89 LOC. import java.awt.*; import java.util.Scanner; import javax.swing.*; public class Main extends JFrame {; public Main(int n) { setSize(900, 900); setTitle("Pythagoras tree"); add(new D...

Java2d: JPanel set background color not working

I am having the below code. public VizCanvas(){ { this.setBackground(Color.black); this.setSize(400,400); } } It worked fine and displays the panel in black background. But when I implement the paint method, which does nothing, the color changes to default color i.e gray. I tried to set graphics.setColor() but...

Java2d: Translate the axes

Hi, I am developing an application using Java2d. The weird thing I noticed is, the origin is at the top left corner and positive x goes right and positive y increases down. Is there a way to move the origin bottom left? Thank you. ...

draw an arc given 3 points in SWT

iam using the swt java library and iam having a problem. the gc draw arc method takes the following arguments GC.drawArc(int x, int y, int width, int height, int startAngle, int endAngle); but i want to be able to draw the arc using 3 arguments : the source ,destination and control points. is there any formula to convert between tho...

Java2D: Capturing an event on a Line object

I have a JPanel which has a line, circle etc..Now when I click on the line, will the event get reported as a line event or a general jframe event. I need to be able to move the line, if the user clicks on the line and moves it. Is this possible in Java2d. Thank you. ...

"Zoom" text to be as big as possible within constraints/box

First problem: You have 400 pixels width to go on, and need to fit some text within that constraint as large as possible (thus, the text shall use that amount of space). Throw in a new constraint: If the text is just "A", then it shall not zoom this above 100 pixels height (or some specific font size). Then, a final situation: Linebrea...

Java2d: Option to show a selection window when mouse is dragged.

Hi, I have a image in Java2d and I would like user to give an option to select any rectangle portion of the image by left clicking and dragging the mouse.(similar to mspaint). How is this actually done? Thank you. ...

Java2d: Increase the line width

Hi, I want to increase the Line2D width. I could not find any method to do that. Do I need to actually make a small rectangle for this purpose? Thank you. ...

Java2d: Set gradient for a lines

Hi, I am having multiple points in a plane and some hundreds of lines pass through those points. Some points can have more lines passing through them than other points. I want to show some kind of more gradient or brightness associated with lines crowded together. Is this possible to do in java2d. Please refer to this : http://ft.ornl....

How can I clip strings in Java2D and add ... in the end?

I'm trying to print Invoices in a Java Swing applications. I do that by extending Printable and implement the method public int print(Graphics g, PageFormat pf, int page). I would like to draw strings in columns, and when the string is to long I want to clip it and let it end with "...". How can I measure the string and clip it at the r...

How can I print a text in two columns using Java Swing?

I have a longer text saved in a String. I would like to print the text in two columns on a single page. How can I do this using Java Swing? I don't understand how I can wrap the text when it's time to use a new line. I have read Lesson: Printing in the Java tutorial, but I haven't found any useful methods for working with text or String...

Occasional InterruptedException when quitting a Swing application

I recently updated my computer to a more powerful one, with a quad-core hyperthreading processor (i7), thus plenty of real concurrency available. Now I'm occasionally getting the following error when quitting (System.exit(0)) an application (with a Swing GUI) that I'm developing: Exception while removing reference: java.lang.Interrupted...

Making a checkerboard-style with graphics (java applet)

OK so, I am making an applet that paints 32x32 square tiles (to make a map) and my problem is that they are going diagonally when I want them to go 8 by 8 (hence the way the array is shaped 8 by 8). So... how do I fix this? Thanks. Anyway, since the code bbcode is being a butthead... here is the pastebin URL :-) http://www.danflow.past...

Can't draw thin lines with Java2D

I'm trying to draw a polygon with a stroke of 1 pixel. Because the entire polygon is scaled by 100, I set the line width to 0.01. For some reason though, the polygon gets drawn with an on-screen line width of what looks to be 100 pixels instead of 1. I'm using GeneralPath as the polygon shape. Thin lines do get drawn if I use the same a...

Using java2d user space measurements with TextLayout and LineBreakMeasurer

I have a java2d image defined in user space (mm) to print an identity card. The transformation to pixels is by using an AffineTransform for the required DPI (Screen or print). I want to wrap text across several lines but the the TextLayout does not respect user space co-ordinates. I was using the following to write wrapped text to a re...

Is there a 100% Java alternative to ImageIO for reading JPEG files?

We are using Java2D to resize photos uploaded to our website, but we run into an issue (a seemingly old one, cf.: http://forums.sun.com/thread.jspa?threadID=5425569) - a few particular JPEGs raise a CMMException when we try to ImageIO.read() an InputStream containing their binary data: java.awt.color.CMMException: Invalid image format ...

JTable cells not rendering shapes properly

I'm trying to render my JTable cells with a subclassed JPanel and the cells should appear as coloured rectangles with a circle drawn on them. When the table displays initially everything looks OK but then when a dialog or something is displayed over the cells when it is removed the cells that have been covered do not rendered properly an...

Override paintComponent in Netbeans GUI

I've added a JPanel to my Netbeans generated GUI, and add a JPanel BoxThing that overrides paintComponent and draws a small red box, but it doesn't display, paintComponent never even gets invoked. If I instantiate my own JFrame and put a JPanel containing a BoxThing in it, it works fine. I've seen this question asked a few other times o...

Operations on Java Swing

In my project,I will get the coordinates of some points from an XML file,and create some visual components using this information ? I am planning to give these components to a Java swing frame or panel. However,The users are supposed to click on the figure(which I will construct using Graphics 2d libraries) and select two points and give...