paintComponent (JComponent.paintComponent(Graphics g)) is a method that Java Swing engine calls on JComponent, in order to draw it using the passed Graphics.

learn more… | top users | synonyms

1
vote
1answer
42 views

Do I need to extend JPanel for paintComponent?

Can anyone give me a link (I have looked, almost, everywhere) to the documentation about how to use paintComponent, I am just looking at displaying a .png that I can change the x, y co-ords (from ...
0
votes
1answer
32 views

Adding multiple graphic objects to one JFrame

Here is my code it is a guy and a background but only one thing shows up at a time or sometimes nothing at all. I have a brain class, a frame class, a redPlayer class, and a background class. The way ...
0
votes
1answer
35 views

Making a graphics object move

In my code I override the paintComponent method and draw a rectangle inside JPanel. The JPanel is then added to JFrame and I use a method that updates the position of the rectangle via a Thread. The ...
0
votes
1answer
58 views

NullPointerException in java exercise assignment

He I am a beginner in java and I am working on a exercise where I need to draw a car. The code in my book does not work and I don't know why. I am not a total noob to java I know classes, objects, ...
0
votes
3answers
39 views

Label inside Circle

I want to put text ( must be formatted with HTML, so I can't use drawString in PaintComponent) inside Circle. Problem is that "paintComponent" is called after drawing label, so it covers my text. How ...
0
votes
3answers
46 views

Dynamically change Background Image of a JPanel

Trying ti change the BG image of a jpanel but i cant call poaint on any normal method, it works great when i'm building the constructor but i don't want to rebuild the constructor. Ideas? ...
0
votes
1answer
65 views

How to set each rectangle color randomly with setcolor

I'm trying to make 3 different colors which are red,blue and green. My goal is when a rectangle created, i want to call the color function. The colored box should moving down, but when it placed other ...
1
vote
1answer
27 views

Grey screen in Netbeans

so i using netbeans, and i'm starting to get into coding games... and i've done this so far with no errors, however when i run it just a grey box with my title "zachs game appears and thats it.... ...
0
votes
1answer
31 views

Multiple problems regarding Java paint program while painting

I have a Java paint program, and I've got two problems to do with it. Both problems are relatively simple, and just regard how the mouse input is handled and how the image uses colors. Here's a photo ...
0
votes
1answer
52 views

paintComponent not working

this may be a silly question but How do i call the paintComponent? Its not displaying the object at all. its within the, public class Ball extends JPanel implements Runnable. public class Balls { ...
2
votes
1answer
46 views

Why do statements get executed more than once in paint or paintComponent methods?

I am trying to draw and paint some geometric shapes based on some calculations inside the paint() or paintComponent() methods. However, I realized that the printing and other calculation statements ...
0
votes
3answers
62 views

Why doesn't this Java paint program paint more than one oval?

I have a Java paint program that uses a custom JPanel to paint on. While when clicking on the JPanel paints a small oval (or circle, if you will), the oval disappears each time you click on another ...
0
votes
3answers
67 views

How do I make this alternate colors by just using the spacebar?

import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.border.*; public class TrafficLight extends JFrame implements ActionListener { JButton b1, b2, b3; ...
0
votes
1answer
41 views

Move a rectangle in a JPanel using the keys

I have a class called "DisplayPanel" (which extends JPanel) and I draw a square there that comes from a class called "Square" (which extends JComponent). How to move a rectangle in a JPanel using the ...
1
vote
2answers
42 views

Swing Worker : function get()

My problem is that I don't understand how the swingworker works because what I'm trying to do is to make fa=worker.get() because I have a long method which compute a lot of points running in ...

1 2 3 4 5 35
15 30 50 per page