aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Drawing on a JFrame that has a Shape Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing on a JFrame that has a Shape" Watch "Drawing on a JFrame that has a Shape" New topic
Author

Drawing on a JFrame that has a Shape

Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
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

Joined: Oct 13, 2005
Posts: 39396
    
  28
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

Joined: Jan 24, 2013
Posts: 23
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

Joined: Oct 13, 2005
Posts: 39396
    
  28
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

Joined: Oct 13, 2005
Posts: 39396
    
  28
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

Joined: Aug 10, 2005
Posts: 687
    
    1
Also posted at: http://www.javaprogrammingforums.com/awt-java-swing/23837-drawing-jframe-has-shape.html#post96081
Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
Norm,
Thanks. Forgot to put it on this one as well..
Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
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

Joined: Oct 13, 2005
Posts: 39396
    
  28
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

Joined: Aug 10, 2005
Posts: 687
    
    1
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Drawing on a JFrame that has a Shape