Results 1 to 3 of 3
  1. #1
    Zorobay is offline Member
    Join Date
    Feb 2010
    Rep Power

    Default JPanel not visible? Am I stupid!?

    Hi, I got this simple code:

    Java Code:
    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class paint extends JFrame{
    	JPanel panel = new JPanel();
    	public void paint(Graphics g){
    		g.drawRoundRect(20, 20, 50, 50, 10, 10);
    	public static void main (String[] args){
    		paint p = new paint();
    	public paint(){
    		setSize(300, 200);
    Now why the hell can't i see the JPanel?! I have dont almost the exact same thing in another program, and it works perfectly =( I can see the drawn "roundrect", but there is no background. Also, why does setBackground, and setForeground never work on JFrame??


  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Rep Power

    Default Re: JPanel not visible? Am I stupid!?

    try these bounds:

    g.drawRoundRect(20, 50, 50, 50, 10, 10);

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: JPanel not visible? Am I stupid!?

    Please read the Swing tutorials first. You are doing so many things wrong I have to wonder if you haven't done this most basic step yet.

    For example, you are
    • Drawing right on the JFrame itself instead of in a JPanel's paintComponent method
    • Covering up you're what you're drawing by putting a component on top of it
    • Using wrong Java naming conventions
    • trying to set component's sizes directly rather than preferred size and calling pack() on the JFrame
    • setting background and foreground colors of a JFrame (this does nothing at all useful)
    • ...

    Also please search this forum for sample code that shows drawing in Swing applications. There are many such examples around here, I know, because I've written a few.
    Last edited by Fubarable; 03-23-2012 at 10:28 PM.

Similar Threads

  1. Stupid mistake, maybe?
    By knox in forum New To Java
    Replies: 1
    Last Post: 11-10-2011, 08:39 AM
  2. Replies: 0
    Last Post: 02-15-2011, 11:16 PM
  3. I need an idea with something really stupid
    By blf_titi in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-27-2010, 03:24 AM
  4. Stupid error
    By dewitrydan in forum Java Applets
    Replies: 3
    Last Post: 08-09-2010, 01:29 PM
  5. Problems with setting the menubar and a JPanel visible
    By leitbug06 in forum AWT / Swing
    Replies: 1
    Last Post: 03-06-2009, 11:46 PM

Posting Permissions

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