• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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.
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!