This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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.
Joined: Jan 24, 2013
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?
Joined: Oct 13, 2005
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.
Joined: Oct 13, 2005
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