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
2 answers

Draw new graphics components (ie circles) when event happens

Im working on a very simple program. What I want to do is have a new circle added when firstButton is pressed (program is currently as it is after making sure I had events working right). I know I need a paintComponent method somewhere, and possibly…
0
votes
1 answer

Issue painting BufferedImage

I'm working on a program that will read a folder of images into a JList, and the picture that is selected in the JList will be drawn into a JPanel. I have two classes: ImageViewerPanel, which creates the panel to display the selected picture. I…
user1727668
0
votes
1 answer

Adding JInternalFrame to fsem frame

I am trying to add a jinternal frame to a frame that is in full screen exclusive mode. However when i add it it fills up the whole screen with white. Here is my code. JFrame f = new JFrame(); f.setTitle("Platform Game"); …
Josh Sobel
  • 1,268
  • 3
  • 14
  • 27
0
votes
2 answers

I neither see the label on the button nor see it painted in green. Why is that ?

The following code places a button onto the panel. But there is a problem.I neither see the label Click Me on the button nor I see the button painted in green. Why is that ? import javax.swing.*; import java.awt.*; class Tester extends JButton { …
Y.E.P
  • 1,187
  • 6
  • 20
  • 40
0
votes
2 answers

repaint one part of JPanel

I need to paint google and yahoo access time in x-y axis coordinate System. Now I have drawn x-y axis coordinate system. public void paintComponent(Graphics gl) { Graphics2D g = (Graphics2D) gl; g.setColor(new Color(222, 222, 222)); …
0
votes
2 answers

I'm Need Help Adding My Paint Component to the Frame in a Class

I need help making what I am trying to paint visible on the screen. I was able to set it up properly in the main, however I feel like it would be more organized to keep everything in their own classes. The window will show up, but nothing will be…
0
votes
1 answer

ImageIO.read preventing paintComponent from executing?

I am trying to a sprite image from a sprite mesh using BufferedImage and ImageIO. There is a separate class which handles the loading and storing of sprite images; this is where the problem seems to be. I load the sprite mesh into a BuffereImage…
0
votes
2 answers

Passing value from JFrame to JPanel

I am trying to draw a histogram of the Color values of the pixel of an image. I have done the job of getting the values but I want to draw the Histogram from that values. I am trying to draw it on the panel using paintComponent() method.…
prasad
  • 387
  • 3
  • 4
  • 13
0
votes
5 answers

How to paint rectangles adjacent in Swing?

I am trying to implement Tetris in Swing, for that I am trying to draw rectangles adjacent to each, but the second rectangle is not coming adjacent to the first. Also if getPreferredSize() returns anything less than 50,50 then nothing shows up in…
Mahendran
  • 2,191
  • 5
  • 24
  • 40
0
votes
1 answer

Graphics2D animation, cant understand why paintComponent only draws the shape one time and then stops

Graphics2D animation, cant understand why paintComponent only draws the shape one time and then stops. I Also can't understand why my timer counter variable isn't incrementing. I've been banging my head against this for over an hour, can anyone…
Rafael Rondon
  • 27
  • 1
  • 4
0
votes
1 answer

method paintComponent(Graphics g) doesn't work

I'm trying to display the Mandelbrot set on a JPanel, and this is my code. I really don't understand why the image drawn on BufferedImage wasn't display on my JPanel. Can anyone show me the problem in my code please ? public class MainPanel1 extends…
Trung Bún
  • 1,117
  • 5
  • 22
  • 47
0
votes
1 answer

Paint on top of a JComponent

I have a JPanel which has few JComponents added to it. I have overridden paintComponent method of JPanel where I am drawing some shapes on JPanel. public void paintComponent(Graphics g){ super.paintComponent(g); g.fillOval(20, 6, 12, 12); …
Deepak Chaudhry
  • 219
  • 4
  • 12
0
votes
0 answers

Custom Java Component Not Drawn Correctly

I have a custom button that is not being drawn properly. It shows up as a dot in the upper left hand corner. I have three classes. One for the button, one for the menu or drawing of several buttons and a main class that calls the menu. Class 1 -…
lostdev
  • 736
  • 8
  • 23
0
votes
1 answer

To Add a Timer to paint

my program currently reads from a text file and paints different coloured circles depending on the next value in the array. at the moment i am reading the first 10 values in the array so there should be 10 painted circles. These circles all paint at…
0
votes
1 answer

swing add image not working

So I made the class public class ImagePanel extends JPanel { BufferedImage lionImage; public ImagePanel(){ try { lionImage = ImageIO.read (new File ("imgres.jpg")); } catch (IOException e) { e.printStackTrace(); …
user1817988
  • 237
  • 2
  • 5
  • 11
1 2 3
99
100