Questions tagged [paintcomponent]

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

paintComponent is responsible for drawing contents of the JComponent, excluding border and possible children. Same as Canvas.paint, it may be overridden but is seldom called directly.

For custom Swing JComponent, it is overridden to paint a deeply custom content, in somewhat similar fashion as paint(Graphics) is overridden for Canvas (border and children as still painted as by default).

The passed parameter (Graphics) is actually Graphics2D and can be casted to use advanced features.

Standard Swing components delegate the call to the attached ComponentUI that paints the component by the rules of the current skin (look & fell).

1651 questions
0
votes
1 answer

paintComponent() not being called when repainting

I have been working on a program that requires the painting of lines on an image when triggered by a mouse drag event, however within my code when the call to paintComponent is made through repaint() the paintComponent method doesn't execute. I have…
Mochi
  • 71
  • 1
  • 11
0
votes
2 answers

How to draw a vertical line in JPanel at a specific position?

I am trying to design a timeline for this media playback application using a JPanel. In order to provide an indication of the current video frame with respect to the timeline, I need to be able to draw a vertical line at a specific x-coordinate in…
Justin
  • 742
  • 5
  • 17
  • 34
0
votes
1 answer

JPanel not displaying in JFrame after paint is called

I am currently imlementing a simple GUI interface to interact with a Lego Mindstorm NXT. My current issue resides with a paint issue on my interface. When my MainUI loads it calls a method called GirdPanel() which sets up my GridPanel. The MainUI,…
ErichNova
  • 27
  • 2
  • 11
0
votes
1 answer

Java : My paintComponents() method is never called

Here is my code. I have 4 classes, an abstract class (GeoShape), a Rectangle class that extends GeoShape, a GraphicsPanel containing my GeoShapes and trying to draw them, and a Launcher class. GeoShape.java public abstract class GeoShape { …
Rob
  • 15,732
  • 22
  • 69
  • 107
0
votes
2 answers

Trying a Java pong

I'm trying to do a Java Pong game. I have very little experience with Java and need some help. I've read a lot of stuff online, and below is the code I've come up with. I've created the following classes, but all I get is a grey screen. I'm just…
dead_jake
  • 523
  • 2
  • 12
  • 30
0
votes
1 answer

I made a java application. The class is extended from javax.swing.JPanel

the paintComponent(Graphics) is overrided. But when I launch the program, it just displays the content of old another window which was at the place of my application's window.I tried minimizing, maximizing, clicking, typing and several such things…
Govind Balaji
  • 639
  • 6
  • 17
0
votes
1 answer

painting a dot at click

Hello I want to know how to get the position of the mouse outside the method MouseClicked this I need for drawing a dot at the place where someone clicks.. this is the code that I use now. Can someone help me with this? Dot punt = new…
Reshad
  • 2,570
  • 8
  • 45
  • 86
0
votes
2 answers

How can I draw things using this Java GUI API?

My instructor has defined this API for graphics. It's very simple but I've spent an hour or two now trying to figure out how to make simple Graphics manipulations show up. So I have a class T which extends TopLevel and it is my main frame. I also…
jaynp
  • 3,275
  • 4
  • 30
  • 43
0
votes
4 answers

JLabel not showing

I'm in the process of finishing up a game and I've reached a point that has made me extremely frustrated. It's probably a simple fix and something I'm overlooking, so maybe you guys can help me out. I'm trying to get a series of 5 JLabels to show…
user1642463
0
votes
1 answer

Undo and move functions with freehand drawing

I'm currently trying to write a Java application which would allow freehand drawing and later, the moving and deleting of each squiggle drawn. I'm guessing my best bet would be to have each click and drag create a separate entity but I've no idea…
Klaabu
  • 337
  • 1
  • 2
  • 9
0
votes
1 answer

no response to my code

I was trying to learn applets and on executing this code, there are no compile-time errors but the problem is that i m not getting any response to my code. i used simple notepad and appletviewer to get it done. On clicking on the applet, the…
0
votes
1 answer

nothing shows up in Java's paintComponent. How do I fix this?

In Java, I need to draw a simple line with the paintComponent. Here is my attempt, but nothing was shown when I executed the program. Please show me the correct way of doing this. import javax.swing.*; import java.awt.*; public class DrawLine…
0
votes
1 answer

JInternalFrame image bag

I have a program, with JFrame and JInternalFrames inside. So, when I try to set background with this code: BufferedImage myImage; myImage = ImageIO.read(new File("C:/5/JavaLibrary2/background.jpg")); ImagePanel Image = new ImagePanel(myImage); …
JohnDow
  • 1,242
  • 4
  • 22
  • 40
0
votes
1 answer

Retrive clicked component from a panel-drawed composite tree

I have a composite tree. I've drawn this tree to a JPanel width Graphics object via overriding paintComponent(Graphics gr). My problem is: how can I access which component is clicked? I only figured out trivial and bad solutions, so that's why I…
WonderCsabo
  • 11,947
  • 13
  • 63
  • 105
0
votes
1 answer

creating a radio interface using java swing gui

I'm in a group assignment at university doing a swing GUI course and need some hints. I have to develop and implement a user interface that represents the following below, knobs tuner slider and all. but I have no idea where to start, note this…
Ryan Leach
  • 4,262
  • 5
  • 34
  • 71
1 2 3
99
100