Rectangle « Graphics « Java Swing Q&A





1. Intersecting rectangles    stackoverflow.com

This is an analytical geometry kind of question.I am not sure I can post it here.However I have to come up with a Java function to do this functionality.I have multiple ...

2. How can i create resizable rectangle in java swing?    stackoverflow.com

I need to add a small feature in a project where, rectangle with some trimable text in it, and the rectangle should be resizable. I'm short of time so didnt try out ...

3. Getting coordinates of a component in java    stackoverflow.com

I have a JLayeredPane, and inside the JLayeredPane is a JInternalFrame. What I need are the bounds (x position, y position, width, height) of the content pane in the JInternalFrame. The ...

4. Remove/clear rectangles drawn by Graphics#fillRect()    stackoverflow.com

I've made this to draw bar graphs, but when I do repaint() the new chart is drawn on top of the previous one. After a few repaints with new arrays it ...

5. Drawing transculent rectangle    stackoverflow.com

I was a problem with drawing rectangle using mouse. I have solve my problem and I get results what I want. But I have a small problem. If I want to ...

6. java+Swing: efficient overlay of rectangle or other "sprite"    stackoverflow.com

I'm not quite sure how to phrase this, so bear with me. I have two JPanels in a container JPanel with an OverlayLayout. Both JPanels in the container override paint(Graphics). The ...

7. Snake Game - Collision Error    stackoverflow.com

So I am making a snake game but if i move from one direction to the other really fast then it says I made a collision with the body and ends ...

8. Drawing a rectangle over an existing Graphics page    stackoverflow.com

I have a Java application which draws a drawing. I want to give the user the possibility to mark an area with the mouse (in order to, for example, zoom into ...

9. Drawing rectangle with rubber band effect.    coderanch.com

Hi, I am trying to draw a rectangle with rubber band effect on a swing JComponent. If I draw the rectangle in the mousedragged event of the component, it draws the rectangle with flickering effect. Also, if I include the code in the paint method and call the paint() method through update(), it doesn't go to the paint method at all. ...





10. AWT Rectangle(URGENT)    coderanch.com

11. displaying rectangles efficiently...    coderanch.com

I have been working on a component that uses a custom paintComponent() function that is rather complex. It can take upwards of a tenth of a second under fairly normal circumstances, and for that reason, I only call repaint() when I absolutely need to. (Meaning the display would actually change), but I have now added "drag selection" functionality to my component, ...

12. Rectangle constructor ?    coderanch.com

Dear all ranchers, I read this in the Java SE 1.4.1 API doc: ====================================================== Rectangle(int x, int y, int width, int height) Constructs a new Rectangle whose top-left corner is specified as (x, y) and whose width and height are specified by the arguments of the same name. ====================================================== But I found the first two args really represent the "bottom-left" corner ...

13. Paint rectangle won't stay displayed!    coderanch.com

14. round edged rectangle    coderanch.com

15. How paint non-rectangular java.awt.geom.Area or break Area into Rectangles?    coderanch.com

I have a window that has rectangles (set at runtime) which are drawn a certain way and then the leftover area needs to be drawn in. (See below) I have been unable to use: area.subtract( new Area( rectangleDrawnSpecial ); graphics.setClip( area ) paint( graphics ); Because Graphics does not support non-rectangular Shape objects. I was thinking of breaking up the leftover ...

16. How to make rectangle drawn to be vissible when a new rectangle is drawn    coderanch.com

Hello, Please some one help with this, actually what i m tryin to do is, when i mouse click n drag the mouse n release it , i want a rectangle to be drawn. and when i click on another location then also i want a rectangle to be drawn and the previusly drawn rectangle should also be vissible. I am ...





18. Rectangle outcode() not working quite right    coderanch.com

I wrote the following to try to capture if the rect is top bottom right left, however it doesnt work right. If I replace the statements eg lets say for top to code==2 || code ==6 || code ==3 it works fine. Any idea what im doing wrong code = nodeRect.outcode(currentRect.getX(), currentRect.getY()); if(code & Rectangle.OUT_TOP) != 0 || (code & (Rectangle.OUT_RIGHT ...

20. Fiiled Rectangle    coderanch.com

21. Moving and resizing a rectangle around    coderanch.com

I had an assignment whihc required exactly that. I used a Rectangle2D object for the drawing, encapsulated inside what I called a RectangleShape object (to avoid confusion with other classes). Note the Rectangle2D and Ellipse2D both inherit from the java.awt.geom.RectangularShape class, which has methods to set its bounding box from a diagonal or from its corners. Resizing: I added a MouseMotionListener ...

22. Problem when repainting rectangles    coderanch.com

Hi! I want a user to draw rectangles in a Indesign fashion. Yoy should be able to resize and so on. The problem is that when I drag the mouse real fast the rectangle moves to a position that is not correct If someone could look at this code. If you press the 1 button you can select rectangles and move ...

23. Do you people have a code in Swing such that 2 rectangles doesnt overlap when created    coderanch.com

Hi all, I have a Swing application. In one of the UI, through a popup menu, we create a rectangle.. Like this we can create n number of rectangles on the UI.. There is an option to rotate the rectangle. When i try to rotate the rectangle, the application should not allow one rectangle to overlap with other. For eg. There ...

24. Problem in drawing a rectangle .....    coderanch.com

Hello, I'm doing a project in java using swings ,im able to create a panel and frame but i have a problem in event handling.I have added the MouseMotionListener but it's giving some error .Here i want to draw a rectangle when the user clicks and drags the mouse button and releases a rectangle has to be drawn.can somebody help me ...

25. Problem in finding the bounds of rectangle.....    coderanch.com

Hello, How to find the x and y co ordinate of a rectangle in terms of number. Is there any method .I want it to return the x y co ordinate of that rectangle. There is getBounds() which returns a rectangle itself but i need in terms of values. How to do this? Thanks in advance,

26. how to persist rectangle?    coderanch.com

27. how to draw rectangle like corelDraw?    coderanch.com

I assume you have gotten the drawing of the rectangle working now. Here are some things to consider when implementing the other points: You need to think of what constitutes "selecting the rectangle" - which events do you need handle, and under which conditions should you consider a rectangle to be "selected"? You also need to indicate which rectangle is selected ...

28. round rectangle with only top corners rounded    coderanch.com

Yea i've been searching and only found the obvious, which is using a roundrectangle, but that's not going to work. It's the hard coding of the pixels, which would be drawing the lines of the corners by hand, so to speak, that i've never done before. I guess there will have to be a first for everything...

29. How can I Move Rectangle?    coderanch.com

Here is the code I have written and I am confused to use move method and can anybody tell me how can i move rectangle import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; public class BackgroundApplet extends Applet { public void init() { setBackground(Color.WHITE); } public void paint(Graphics g) { g.setColor(Color.BLACK); g.drawRect(0,0,100,100); //first rectangle g.drawRect(120,0,100,100); // beside first rectangle g.drawRect(0,120,100,100); // down to ...

30. Rectangle Not coming+swing    coderanch.com

31. Colouring a rectangle    coderanch.com

Hi This is my first post, I want to draw a rectangle with a blue colour, but the problem is that the method is not recognized (this thing drives me mad) can you please help me to set the colour. import java.awt.*; public class MonRectangle extends Rectangle { //Les coordonnes int PosX, PosY ; int width, height; //Constructeur public MonRectangle(int PosX, ...

32. Drawing a rectangle but at an angle    coderanch.com

Hello i'm making a word search game. I want the user of the application to be able to circle the words they find. At the moment the user can cross out the word. That was no problem as I used drawLine(). Which takes the x1, y1, x2, y2 co-ordinates as arguments. But I can't do the same with drawRectangle or drawRoundRect, ...

34. How to change color of area contained by rectangle    java-forums.org

My application is basically a sketchpad used to draw something like organization chart. Question is, whenever i hover the mouse over the nodes which is basically a rectangle drawn using the paint method, is there any way i can change the color of the portion of the sketchpad being occupied by the rectangle?

36. Changing squares to rectangles in simple Swing program    java-forums.org

Hello everyone, I'm pretty new to Java and am having some issues with what is probably a very simple problem. I have written the following program that displays a 10x10 color matrix of squares whose colors are randomly generated and are randomly changed upon being clicked by a user in the window. However, if I wanted to change these squares to ...

37. draw a translucent black rectangle    java-forums.org

Well I'm using a Graphics2D object for drawing everything on the image is an Image object drawn on with draw image. I was wondering was either where I should look to find the method for drawing the rectangle or what the method is that does this kind of drawing because I looked in both Graphics and Graphics2D and couldn't find it. ...