PaintComponent « Graphics « Java Swing Q&A





1. The Need To Restore Graphics Original State When Overwritten paint or paintComponent    stackoverflow.com

I realize most of the Java code to overwritten paint or paintComponent, most of them doesn't restore the old state of graphics object, after they had change the state of graphics ...

2. Why is paint()/paintComponent() never called?    stackoverflow.com

For the last two days I have tried to understand how Java handles graphics, but have failed miserably at just that. My main problem is understanding exactly how and when ...

3. why is my code executing paintComponent(Graphics page) twice?    stackoverflow.com

This is getting on my nerves and it probably something silly on my part but I can't figure out why my paintComponent is being called twice, if you run my code ...

4. protected void paintComponent(Graphics g)    stackoverflow.com

We can override the paintComponent(Graphics g) method of JComponent. It is called automatically to refresh the screen. What can I do that is called regularly, for example every 100 ms. Is this possible?

5. Passing an abstract Graphics object to paintComponent()    stackoverflow.com

In Java, when using the paintComponent() method for a JPanel, the parameter that is passed is an object from the abstract class Graphics. Since using an abstract object doesn't make sense, ...

6. problem with super.paintComponent(g)    stackoverflow.com

This is the snippet :

protected void paintComponent(final Graphics g) {

 Runnable r=new Runnable() {

 @Override

  public void run() {
   while(true) {
     super.paintComponent(g);  // ...

7. Paint another component in paintComponent    stackoverflow.com

I use SwingPaintDemo2 from Java Tutorials: http://download.oracle.com/javase/tutorial/uiswing/examples/painting/SwingPaintDemo2Project/src/painting/SwingPaintDemo2.java I modified it like this:

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Draw Text
    g.drawString("This is ...

8. Odd graphical bug: a copy of component A is painted on component B. HELP! (java)    stackoverflow.com

I have made a simple paint program in which you can use a brush-tool to paint some different colors and erase (simply paint in white). It works fine, but I have a ...

9. Simple custom Swing JComponent always flat    stackoverflow.com

I'm just playing with Swing and I'm working on a really simple Swing component. I have a component inherited from JComponent class and its UI inherited from ComponentUI. The paint() method ...





10. drawingLines in java using Graphics    stackoverflow.com

Heres an example of a method to draw 1 line passing in two points

public void paintComponent(Graphics comp) {
   Graphics2D comp2D = (Graphics2D)comp; 
   comp2D.drawLine(0,60,100,60);
 }
Im trying to ...

11. paintComponent() not drawing graphics correctly    coderanch.com

Hi. I'm having a problem with painting some graphics. My program is basically a Little Man Computer simulation showing a character walking around the screen. When he reaches any one of the pre-determined points in the panel (i.e. a certain y-coordinate), I want to use an if statement in paintComponent() to determine that coordinate and draw a rectangle with some text, ...

12. calling paintComponent(Graphics g)    coderanch.com

13. Array of colors in paintComponent method.    coderanch.com

I can't seem to figure out how to fill the polygons I made with random colors. My assignment specifically says to generate 10 random colors, use an array to store the 10 colors and then use the colors to fill the ten polygons I made. Right now my array seems to just hold numbers between 0 and 255, and I don't ...

14. removing a painted component via paintComponent leaves a residue    coderanch.com

hi new mates, its just my first time, here. hello. i hope i cant state my ideas properly. im about to create a , you can say a complex GUI, which will have tons of animated and customized Components such as Panels(panes) Buttons etc.. , and as of now, im on the start, trying to create a sliding looking pop window ...