File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing on a JFrame that has a Shape

 
Tim Alvord
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have created a JFrame for my application that has a custom shape. In this case a simple circle. How can I draw my own edge around the edge of the shape? I have tried adding the code to both paint() and paintComponent() and have noticed that in the debugger, it never gets to either paint routine. Any ideas as to how to do this?


 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by putting the @Override annotation before those two methods and compiling again.
You have found a setShape method, but did not read what it does.
You usually add a panel to the frame, and draw on that, having overridden its paintComponent method, which should have protected access. Always precede your first statement with super.paintComponent(g); and then copy what you have already written into it.

You should move all that code out of the main method into a constructor (or initGUI) method in your GUI class. All its fields should be instance fields; none of those GUI components should be static.
 
Tim Alvord
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell,
Thanks always for your excellent help. I assume you are talking about creating a "circlularJPanel" class instead? I am having a problem seeing how that would work, since I want the entire JFrame to be circular. If I set the circularJPanel's Shape to the circle, it will affect the JFrame it's contained in?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I have misunderstood the problem

I have never tried a round frame; I thought you were trying to draw a circle on it. I shall try a round frame and see what happens.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create a frame, set it undecorated, and add things to it. You can also give it a shape (eg round). But I cannot see how you can set a shape to a panel or another Component.
You can set a border on a component; I shall try whether you can set a border on a frame. I don’t think you can; no setBorder method on frames on Eclipse, at least.

Sorry, not sure I can help any more. As you said, you can try drawing circles. This is as far as I got
 
Norm Radder
Ranch Hand
Posts: 707
3
 
Tim Alvord
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm,
Thanks. Forgot to put it on this one as well..
 
Tim Alvord
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm,
I understand what you were trying to do in your example. Thanks. Here's what I got based on your suggestions:

 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Also posted at: . . .
Thank you for noticing. And any similarity between what you found and what was posted on this forum previously is I presume entirely coincidental?
 
Norm Radder
Ranch Hand
Posts: 707
3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
entirely coincidental?

Sorry, I don't understand what you are trying to say.

My post was to provide posters with a link to other sites where the OP had posted this question.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic