Results 1 to 3 of 3
  1. #1
    Nhatmeister is offline Member
    Join Date
    Aug 2013
    Rep Power

    Default swing - paint() help !

    This is my code to paint a picture on a JFrame type.
    After painting, it automatically repaint and resize the picture to about 1/10 of actual size.

    public void paint(Graphics g)
    int x = 0;
    int y = 0;
    //retrieve data from ArrayList rockInfo to build
    //color spectrum representation.
    //remove the first element for grid size.
    int gridSize = rockInfo.remove(0);

    int myColor = 0;
    int cCount = 1;

    for(x=0; x<gridSize; x++)
    for(y = 0; y<gridSize; y++)
    myColor = rockInfo.get(cCount);
    Color nextColor = new Color(myColor);
    g.drawLine(x, y, x, y);

    What's causing it to do this ?

    Thank you

  2. #2
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    South Africa
    Rep Power

    Default Re: swing - paint() help !

    Try removing the code "super.paint(g);"
    You are causing the paint method to run twice
    Sorry, I only speak machine language. Yes or a No?:confused:

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: swing - paint() help !

    Nope! super.repaint(g) is appropriate, if, one wants to paint on a JFrame. However, that is incorrect technique. The OP should extend JPanel and add that to an instance of JFrame. Then override paintComponent () and draw the shape. Then, we can figure out what is happening.

    @OP - please provide an Short, Self Contained, Correct Example that demonstrates the problem. Include all relevant code and make certain it will compile and run. In your case the code should be no more than 25 lines.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Paint--- trying to paint an oval
    By noobie_nate in forum Java 2D
    Replies: 2
    Last Post: 06-05-2013, 05:45 PM
  2. How to use two paint methods? (Swing)
    By MW130 in forum New To Java
    Replies: 1
    Last Post: 01-25-2013, 05:57 AM
  3. Paint is invalid type for variable paint.
    By minibronya in forum New To Java
    Replies: 3
    Last Post: 05-25-2012, 05:52 AM
  4. Swing: unstabel window paint?
    By t500yo in forum AWT / Swing
    Replies: 3
    Last Post: 06-03-2010, 02:25 PM
  5. help?! paint on top of swing components on JPanel
    By beam2008 in forum AWT / Swing
    Replies: 1
    Last Post: 12-05-2008, 05:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts