PaintComponent « Development « Java Swing Q&A





1. java/Swing issue with paintComponent    stackoverflow.com

The issue I'm having is issue with is I'm trying to get the paintComponent to draw the circle only when the mouse is clicked, dragged, then let go. However inside my ...

2. Who is calling paintComponent?    stackoverflow.com

For some reason, my paintComponent(Graphics g) method is being called infinitely. I can't seem to tell who is calling it, even if I dump a StackTrace in the call (it's an ...

3. paintComponent not being called at the right time    stackoverflow.com

I'm trying to write an app that goes something like this:
- Display a dialog
- When user clicks OK, close dialog, go to main app Here are the relevant code snippets:

public class Owari ...

4. EDT and paintComponent    stackoverflow.com

i redefine the paintComponent method in my component and i try to improve performance. First thing i try is to create a new Thread, inside which i invoke SwingUtilities.invokeLater(new Runnable(){...}); Nothing ...

5. PaintComponent not being called netbeans GUI    stackoverflow.com

I am completely new to netbean's graphics system, and have been struggling with a java textbook. I am trying to produce a simple program to display some things, and have followed ...

6. paintComponent question    stackoverflow.com

What purpose does super.paintComponent(g) serve in this sample code?

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(Color.GRAY);
    g.fillRect(gridX * 50, gridY * 50, 50, ...

7. Using a variable with paintComponent    stackoverflow.com

For a homework assignment, I am trying to paint a box with paintComponent using user inputed variables. I have been able to build what I am need to do using fixed ...

8. List for holding data    stackoverflow.com

i receive float data from the network every 400 ms that i put in 4 arrays of float. I store those arrays in another array, so i have :

float[][] datas ...

9. Swing - paintComponent method not being called    stackoverflow.com

i simply implemented class that inherits JPanel like below

public class Orpanel extends JPanel {

....
    @Override
    public void paintComponent(Graphics g) {
      ...





10. Who is calling the paintComponent() method in my class?    stackoverflow.com

I have a simple class that paints a graphic in a JPanel. This is my class:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;

class Drawing_panel extends JPanel {
    public void paintComponent(Graphics g) ...

11. Feedback please on example program intended to be used as a tutorial    stackoverflow.com

This is a sample program that I intend to post as part of a series of beginner level Java tutorials. Please provide any feedback on improvements that would make example ...

12. Overriding paintComponent    coderanch.com

Hi All, I have a program where I have various Displays added to a JFrame. If I run this: package tetris_1_1; import java.awt.*; import javax.swing.*; import javax.swing.border.*; public class Display extends JPanel { protected Dimension d; protected int width, height; public Display() { } public Display(int width, int height, String title) { d = new Dimension(width, height); setBackground(Color.black); if(title != null) ...

13. paintComponent()    coderanch.com

14. Constant paintComponent calling    coderanch.com

Thank you very much for your help. IT HAS SOLVED THE PROBLEM!!! I have commented out all the repaint() calls and now there is only repaint when I hide and show back the window. I think it was this final repaint call after win.pack; I will check it now by uncommenting the actionlistener repaint calls. It has also solved the problem ...

15. paintComponent() problem    coderanch.com

import java.awt.*; import java.util.Random; import javax.swing.*; public class GradientTest { Random seed; public GradientTest() { seed = new Random(); JTabbedPane tabbedPane = new JTabbedPane(); for(int j = 0; j < 3; j++) tabbedPane.addTab("tab " + (j+1), getPanel()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(tabbedPane); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private JPanel getPanel() { JPanel panel = new JPanel() { GradientPaint gp; protected ...

16. HFJ and paintComponent    coderanch.com

Originally posted by Bob Beerbower: Jeff, thanks for the reply. So the PaintComponent() method in my code is basically telling the system that I need some paint methods to be run, but that its up to the system which ones to run and when? Your wording is a little vague: "I need some paint methods to be run" sounds like a ...





18. How optimize paintComponent?    coderanch.com

Hello, I'm developing an application that draw a shape over an image and then after clic a button, the application calculate all the points that are into the shape and paint it with the same color as the shape. I paint the shape in the paintComponent method. My problem is that performance of the application descends dramatically in the moment that ...

19. New to SWING/AWT : paintcomponent called twice by default?    coderanch.com

Hi, I am a newby to this but i have a simple question for the below simple code. Why is the paintcomponent called twice by default when it is run? import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class DrawTest { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { DrawFrame frame = new DrawFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } ...

20. I can't override paintComponent...???    coderanch.com

yeah I was just trying anything at that point to make it work - it's not like anything else needs to use it, but at the moment, I'm more concerned with getting a functional program than dotting the Is and crossing the Ts. I do try and observe good OO design methodology, but the truth is, I've been teaching myself Java ...

21. paintComponent() troubles    coderanch.com

Hi forum and my warm wishes for a productive (and healthy) new year for you and your family! I have one object that extends JPanel, overrides paintComponent() and initializes/starts other objects, each of them running a thread that is responsible for some stuff, including painting itself on the panel. One design that I tried but it seems a bit botched is ...

22. paintComponent usage    coderanch.com

Hey guys, I understand that all custom painting should be done inside an override of paintComponent(Graphics g)... BUT I have a GUI class which extends JFrame. It is essentially a google earth-like map app, and I want to have a mini map showing the current position, like in video games. I intend to do this by painting on the graphics context ...

23. Trouble with paintComponent()    java-forums.org

I have two subclassed components, a JPanel and a JButton. I've overwritten their paintComponent() methods to handle their display. Problem is, I've put the new JButtons in the new JPanel, and the graphics arent displaying properly. I've done a little testing and found that whenever the JButtons are being repainted, they are calling the JPanels paint methods as well, but the ...

24. paintComponent() Trouble    java-forums.org

package tests; import java.awt.*; import javax.swing.*; public class mainClass { public static basicWindow wnd; public static myCanvas mc; public static void main(String argv[]) { wnd = new basicWindow("Drawing", 320, 240); mc = new myCanvas(200, 200); wnd.add(mc); wnd.display(); } } @SuppressWarnings("serial") class myCanvas extends JPanel { public myCanvas(int sizeX, int sizeY) { setPreferredSize(new Dimension(sizeX, sizeY)); } public void paintComponent(Graphics g) { super.paintComponent(g); ...

25. PaintComponent not working    java-forums.org

First off I would like to say hello to members of the forum as I am new here. I am having a problem with the paintComponent method. I am trying to render an image to the screen when a button is clicked. When I click the button the image is not being displayed. I thought maybe it was a problem with ...

26. paintComponent    java-forums.org

27. Java GUI problem - paintComponent problem?    forums.oracle.com