• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Vertical gray patch in my JFrame?  RSS feed

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've learned Java, but that was two years ago... Now I'm back to it and I've reached Swing components. I have a small problem here. I wrote some programs, which are working fine, except for one vertical gray patch at the right side of the frame/panel. I think it's something probably really small, but I can't figure it out since I'm touching Swing after two years. Can someone please point out to what I'm doing wrong. It's just a small code to display a circle. The circle is displayed, but there's this path next to it. I'm not understanding what it is... it seems like a part of the frame or panel. Please help me solve the problem, I'll really appreciate it! Here's the code -

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Face
{
JFrame frame1 = new JFrame("Smile Please!");

void go()
{
FacePanel face1 = new FacePanel();
frame1.getContentPane().add(face1);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize(500, 500);
frame1.setVisible(true);
}

public static void main(String[] str)
{
new Face().go();
}

class FacePanel extends JPanel
{
public void paintComponent(Graphics g)
{
g.setColor(Color.WHITE);
g.fillRect(0, 0, this.getHeight(), this.getWidth());
g.setColor(Color.BLACK);
g.drawOval(50, 50, 450, 450);
}
}
}
 
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method is : Graphics.fillRect(x0, y0, x1, y1)

You have :



It should be :

 
Roshni Singhania
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh dear!I knew I was making some silly mistake in that code! Thank you so much for pointing it out. Thanks a ton!

Have a nice day.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!